数据不渲染的原因
子组件传过来的时候是配置项,父组件请求接口后改变数据的值,这时图表已生成,但数据不展示
解决方法:需要一个监听机制告诉Echarts重新渲染数据
watch: {
//观察option的变化
echarts_option: {
handler(newVal, oldVal) {
if (this.myChart) {
if (newVal) {
this.initChart(newVal);
} else {
this.initChart(oldVal);
}
} else {
this.initChart();
}
},
deep: true //对象内部属性的监听,关键。
}
},