多次执行 echarts 报 There is a chart instance already initialized on the dom!警告

多次执行 echarts 报 There is a chart instance already initialized on the dom!警告_第1张图片

当前页面,当你多次执行echarts绘制时,控制台会报“ There is a chart instance already initialized on the dom”警告,它的意思是:“dom上已经初始化了一个图表实例”

解决方法:

在绘画echarts的方法内加上判断是否已经存在,存在则销毁即可,代码实例如下:

data() {
	return {
		myRingChart1:null
	}
}
drawRing1() {
      if (
        this.myRingChart1 != null &&
        this.myRingChart1 != '' &&
        this.myRingChart1 != undefined
      ) {
        this.myRingChart1.dispose() //解决echarts dom已经加载的报错
      }
      // 基于准备好的dom,初始化echarts实例
      this.myRingChart1 = echarts.init(this.$refs['myRingChart1'])
}

你可能感兴趣的:(Error)