vue中反复加载echarts会出现这个问题:

There is a chart instance already initialized on the dom.

也很好理解,就是这个dom已经创建过了,由于反复加载,你又创建了一次。但是看到网上的几种方法,比如:

var myChart
if (myChart != null && myChart != "" && myChart != undefined) {
        myChart.dispose();
}

这样的处理,看着没什么问题,但是就是不起作用。我想,原因就是这个警告报的是dom已经存在,那应该避免重新初始化这个dom才对,于是这么处理:

var myRingChart;  

// 如果这个dom不存在  那就不执行
if (document.getElementById(this.ringId) == null) {
   return
} 

this.$echarts.dispose(document.getElementById(this.ringId));

警告取消了。

Logo

前往低代码交流专区

更多推荐