1. 程式人生 > 其它 >vue彈窗中echarts報錯typeError: Cannot read property ‘getAttribute‘ of null

vue彈窗中echarts報錯typeError: Cannot read property ‘getAttribute‘ of null

技術標籤:vue.jsvue彈窗中echarts報錯

今天需要在抽屜裡面繪製echarts圖形 發現個神奇的報錯 不顯示圖形 還報錯 :
typeError: Cannot read property ‘getAttribute’ of null
百度下知道是因為拿不到dom節點 所以報錯 綜合分析下網上的解決辦法 覺得下面的辦法比較簡單 還能順利解決:
在彈窗的彈出事件裡出發一下函式(eg: dialog、drawer 的@open事件)

    openChart() {
      const self = this
      setTimeout(() => {
        //  執行echarts畫圖方法
        self.initCharts()
      }, 0)
    },