天天看點

解決echarts警告提示 echarts.js?1be7:2168 There is a chart instance already initialized on the dom.

解決echarts警告提示 echarts.js?1be7:2168 There is a chart instance already initialized on the dom.

1、分析原因

     主要是因為,我把echats圖表的代碼封裝成一個方法,在頁面中多次調用,而頁面中建立的dom節點都是同一個,每次運作都會init一個echarts執行個體,所有就會出現上面的警告資訊

2、解決方法

      使用echarts.getInstanceByDom()  方法判斷是否已經存在echarts執行個體,如果有則不建立,如果沒有就進行建立

       注意,我在前文中已經說明了,我是把echarts,注冊在vue的 prototype上并用$echarts表示,是以直接使用this.$echarts

解決echarts警告提示 echarts.js?1be7:2168 There is a chart instance already initialized on the dom.