zoukankan      html  css  js  c++  java
  • 项目中报错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)
      },
    

      

  • 相关阅读:
    java面向对象
    Mysql 用户管理
    Mysql备份数据库
    Java方法&面向对象习题
    Mysql 用户管理
    java 方法笔记
    事物与存储过程
    多表操作
    视图 sql语句
    mongodb
  • 原文地址:https://www.cnblogs.com/wangdashi/p/10417524.html
Copyright © 2011-2022 走看看