La palabra clave as debe usarse al presentar echarts, de lo contrario, la introducción no es válida
Introducido en el método principal
error
import Vue from 'vue'
import App from './App.vue'
import echarts from 'echarts'
Vue.config.productionTip = false
Vue.prototype.echarts = echarts
new Vue({
render: h => h(App)
}).$mount('#app')
correcto
import Vue from 'vue'
import App from './App.vue'
import * as echarts from 'echarts'
Vue.config.productionTip = false
Vue.prototype.echarts = echarts
new Vue({
render: h => h(App)
}).$mount('#app')
Introducido en el componente
error
<template>
<div>
<div id="main" style="width: 600px;height:400px;"></div>
</div>
</template>
<script>
import echarts from 'echarts'
export default {
data(){
return{
}
},
mounted(){
this.initEchart()
},
methods: {
initEchart(){
let myChart = echarts.init(document.getElementById('main'));
let option = {
title: {
text: ''
},
tooltip: {},
legend: {
data:['']
},
xAxis: {
data: ['']
},
yAxis: {},
series: [{
name: '',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
}
myChart.setOption(option);
}
}
}
</script>
correcto
<template>
<div>
<div id="main" style="width: 600px;height:400px;"></div>
</div>
</template>
<script>
import * as echarts from 'echarts'
export default {
data(){
return{
}
},
mounted(){
this.initEchart()
},
methods: {
initEchart(){
let myChart = echarts.init(document.getElementById('main'));
let option = {
title: {
text: ''
},
tooltip: {},
legend: {
data:['']
},
xAxis: {
data: ['']
},
yAxis: {},
series: [{
name: '',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
}
myChart.setOption(option);
}
}
}
</script>