TypeError: Cannot read properties of undefined (reading ‘map‘)

控制台报错 TypeError: Cannot read properties of undefined (reading 'map')

我的错误原因:第一次页面渲染的时候,map的对象是undefined或null,

解决方法:在前面加个要进行判断,当有值时再去遍历

// 1、可选链式操作符  ?.
this.array?.map(()=>{ …… })

// 2、&& 判断
this.array&&this.array.map(()=>{ …… })

猜你喜欢

转载自blog.csdn.net/WX_nbclass/article/details/128711850
今日推荐