1.原因:渲染时机不对
如何解决?
(1)在tab的点击事件中使用this.$nextTick,页面加载完毕之后执行延迟回调;
handleClick() {
this.$nextTick(function () {
var myEvent = new Event("resize");
window.dispatchEvent(myEvent);
});
}
(2)接下来在初始化echarts时,Echarts 图表自适应,echarts 图表大小随窗口变动而自适应,直接给echarts图表加监听事件
option && myChart.setOption(option);
window.addEventListener("resize", () => {
myChart.resize();
});
(3)在mounted中加载handleClick方法
mounted() {
this.handleClick()