項目中報錯Cannot read property 'getAttribute' of undefined解決


項目中用到了echarts圖表

每次切換路由的時候,控制台就會報一堆錯誤:Cannot read property 'getAttribute' of undefine

經驗證,發現是設置了圖表自適應導致的,

有多個圖表,然后使用是 addEventListener來進行圖表自適應,但是在離開當前頁的時候,沒有清除,就導致了上面的報錯

mounted () {
    window.addEventListener('resize', this.initEchart, 20)
    this._getLibraryNumber()
  },
methods: {
    // echarts自適應
    initEchart () {
      this.echart = echarts.init(this.$refs.echart)
      this.echart.resize()
    },
}     

 

了解到原因后,當離開頁面的時候,進行清除就可以了

destroyed () {
    window.removeEventListener('resize', this.initEchart, 20)
  },

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM