Unhandled error during execution of native event handler ;Cannot read property ‘children of undefine

1:问题分析

数据能出来,页面正常显示,但是有报错。

[Vue warn]: Unhandled error during execution of native event handler ;意思是执行本机事件处理程序期间出现未处理的错误

TypeError: Cannot read property 'children' of undefined 意思是属性 children未定义

报错处代码:而且点击错误直接定位到了this.categoryList[index]这里得index后面,由此可知是这里有问题

clickFirstCategory(index) {
	this.isActive = index;
				// 点击过快时,商品展示报错(找不到children)
	this.secondCateList = this.categoryList.length > 0 && this.categoryList[index].children;
	this.thirdCateList = this.secondCateList.length > 0 && this.secondCateList[index].children;
}

 2.解决

既然是执行本机事件处理程序期间出现未处理的错误,那么只要处理了这个错误就行。

首先想到得就是try catch,但是虽然错误捕捉到了,但是如果打印catch里的错误日志,还是存在,所以其实只是捕捉了错误,并没有解决

解决办法:改写此处判断条件,问题解决

if (this.categoryList.length > 0 && this.categoryList[index])
	this.secondCateList = this.categoryList[index].children;
if (this.secondCateList.length > 0 && this.secondCateList[index])
	this.thirdCateList = this.secondCateList[index].children;

参考:2021-11-22 VUE3控制台出现'Unhandled error during execution of component event handler'警告解决方法 - 码农教程

猜你喜欢

转载自blog.csdn.net/qq_34569497/article/details/130984828