解决echarts数据更新了图表不更新
问题:做echart图表的时候,如果数据是从接口获取的,那当重新请求接口,数据发生变化的时候echart图表却还是维持原样不更新
<div id="echart" ref="echart"></div>
//获取数据后加载获取echart的方法
this.$refs["echart"].getChart();getChart() {let option = {...xAxis: [data: this.data]};option && myChart.setOption(option);
}
方式一:refs
//获取数据后加载获取echart的方法
this.$refs["echart"].getChart();
方式二:监听
watch: {data() {this.getChart();}
}
方式三:setOption方法设置为true(最屌)
option && myChart.setOption(option, true);