在react当中使用map做遍历的时候,出现报错Uncaught TypeError: Cannot read properties of undefined (reading 'map')
原因:第一次页面渲染的时候,map的对象是undefined,所以在前面加个要进行判断,当有值时再去遍历
错误代码:
正确代码:
在react当中使用map做遍历的时候,出现报错Uncaught TypeError: Cannot read properties of undefined (reading 'map')
原因:第一次页面渲染的时候,map的对象是undefined,所以在前面加个要进行判断,当有值时再去遍历
错误代码:
正确代码: