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

旧城等待, 2023-10-08 21:06 207阅读 0赞

1e94a647ffa9482c9c6804bcd8e03d5e.png

简述:vue项目报错,

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

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

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

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

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

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

发表评论

表情:
评论列表 (有 0 条评论,207人围观)

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

相关阅读