用echarts时,若是存在DOM,就会报存在警告,处理方法删除DOM:bash
echarts.dispose(document.getElementById(id))
复制代码
用echarts时,若是不存在DOM,就会报错,处理方法先检查是否DOM存在:echarts
if (document.getElementById(id) == null) {
return
}
复制代码
最终兼容办法代码:ui
if (document.getElementById(id) == null) {
return
}
echarts.dispose(document.getElementById(id))
this.charts = echarts.init(document.getElementById(id))
this.charts.setOption({})
复制代码