将原来import echarts from 'echarts'换成import * as echarts from 'echarts'
// 基于准备好的dom,初始化echarts实例
this.chart = echarts.init(document.getElementById('chart')),这个极为重要,按这个模板改数据
在
// mounted(){
// this.setChart()
// },中调用
setChart() {
// 基于准备好的dom,初始化echarts实例
this.chart = echarts.init(document.getElementById('chart'))
var option;
option = {
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
data: [150, 230, 224, 218, 135, 147, 260],
type: 'line'
}
]
};
this.chart.setOption(option)
}