业务场景:通常渲染列表的时候 后端不会去返回单独的序号 会返回列表所需要的的data数据
此时拿到res数据之后应该遍历添加index:
let newData = res.map((item, index) => {
item.key = index + Math.random()
item.index = index + 1
return item
})
给数据绑定唯一的key值便于 列表渲染
业务场景:通常渲染列表的时候 后端不会去返回单独的序号 会返回列表所需要的的data数据
此时拿到res数据之后应该遍历添加index:
let newData = res.map((item, index) => {
item.key = index + Math.random()
item.index = index + 1
return item
})
给数据绑定唯一的key值便于 列表渲染