您好,欢迎来到纷纭教育。
搜索
您的当前位置:首页项目中报错Cannot read property 'getAttribute' of undefined解决

项目中报错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)
  },

  

转载于:https://www.cnblogs.com/wangdashi/p/10417524.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- fenyunshixun.cn 版权所有 湘ICP备2023022495号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务