Cannot read property 'forEach' of undefined
程序员文章站
2022-03-04 11:03:44
...
在调bug的时候出现了这个问题,这个问题可能会导致界面出现重复显示的问题
错误代码:
//加载表格内容
if (res != null && res.code == '0000' && res.data != null) {
let ret =[];
res.data.list.forEach(el => {
const item: any = {};
item.studentCode = el.studentCode;
item.studentName = el.studentName;
item.studentScore = el.studentScore;
}
这个就是遍历数据的一个方法。
解决办法就是在遍历之前,先判断是否存在
if (!res.data.list){
return;
}
然后就解决了。
推荐阅读
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object
-
npm ERR! Cannot read property 'path' of null
-
js报错 Cannot read property 'getAttribute' of null
-
微信小程序报Cannot read property 'setData' of undefined的错误
-
webpack报错Cannot read property 'presetToOptions' of undefined
-
Extjs4---Uncaught TypeError: Cannot read property ‘items’ of undefined
-
JavaScript Uncaught TypeError: Cannot read property 'value' of null
-
Cannot read property 'tap' of undefined
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#
-
el-tooltip组件中content使用Vue-i18n报错TypeError: Cannot read property ‘$t‘ of null