解决Cannot read properties of undefined (...)类型的报错

02-27 阅读 0评论

场景:

在项目中,想要获取鼠标的元素,红色区域报错:Cannot read properties of undefined (reading 'grid3D')

解决Cannot read properties of undefined (...)类型的报错,解决Cannot read properties of undefined (...)类型的报错,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,使用,访问,修改,第1张
(图片来源网络,侵删)

解决Cannot read properties of undefined (...)类型的报错

分析:

Cannot read properties of undefined类型的报错,一般是报错元素的前一个元素出了问题,也就是this.option没有获取到。

报错类型一般为两种:

  1. 对象没值的时候
  2. 对象为undefined的时候

对象没有数据的时候为undefined 这个时候访问内部内容就会报错

解决方法:

查看一下this.option,注释掉问题代码,并输入console.log(this.option)

let option = xxx;
this.rateChart.on("mouseover", (params) => {
        // console.log('params',params);
        if (params.target) {
          // console.log("非空白区");
        } else {
        //  console.log("空白区");
          console.log(this.option) 
          // this.option.grid3D.viewControl.alpha =20; // 视角绕 x 轴,即上下旋转的角度
          // this.option.grid3D.viewControl.beta = 70; // 视角绕 y 轴,即左右旋转的角度。
          // this.rateChart.setOption(this.option);
        }
}); 

发现输出undefined,说明没有找到option,查看上下文,发现前面已经定义了option,不需要用this,直接使用即可。

解决Cannot read properties of undefined (...)类型的报错,解决Cannot read properties of undefined (...)类型的报错,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,使用,访问,修改,第3张
(图片来源网络,侵删)

修改后:

解决Cannot read properties of undefined (...)类型的报错

成功解决。

解决Cannot read properties of undefined (...)类型的报错,解决Cannot read properties of undefined (...)类型的报错,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,使用,访问,修改,第5张
(图片来源网络,侵删)

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

发表评论

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

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

目录[+]