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

Console error TypeError: Cannot read properties of undefined (reading 'map')

The reason for my error: when the page is rendered for the first time, the map object is undefined or null,

Solution: add a judgment in front, and then traverse when there is a value

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

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

Guess you like

Origin blog.csdn.net/WX_nbclass/article/details/128711850
Recommended