Uncaught TypeError: Cannot read properties of null (reading ‘getAttribute‘)

04-13 阅读 0评论

Uncaught TypeError: Cannot read properties of null (reading ‘getAttribute‘)

简述:vue项目报错,

Uncaught TypeError: Cannot read properties of null (reading 'getAttribute'),

翻译:无法读取null属性(读取'getAttribute'),

解析:getAttribute()是js获取属性方法,就是getAttribute不能读取null的属性,

这种错误一般出现在使用Echarts和地图后,当切换到空白页面后,重置页面时,就会报类似错误,解决方法就是在报错之前做判断处理;


解决:在触发事件前做判断,假如你是在重置页面大小时触发该事件;

//给页面添加监听事件,如果存在,那再执行;
mounted() {
  this.defineWeek();
  window.addEventListener("resize", () => {
    if (document.getElementById("week")) {
      this.defineWeek();//Echarts方法
    }
  });
},

免责声明
本网站所收集的部分公开资料来源于AI生成和互联网,转载的目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复: 表情:
评论列表 (暂无评论,人围观)

还没有评论,来说两句吧...

目录[+]