for(let i=0;i<=res.data.length;i++){
res.data[i]['class'] = 'biaoqian-red';
}
console.log(res.data);
报错:cannot set property xxx of undefined
原因
因为res.data[i]['class']可能是undefined
,如果再给res.data[i]['class']动态添加属性的话就会报这样的错误解决:
for (let i = 0; i <= res.data.length; i++) {
if(rea.data[i] != undefined){
res.data[i]['class'] = 'biaoqian-red';
}
}