高级前端
vue
【Q154】在 react/vue 中数组是否可以以在数组中的次序为 key

在 react/vue 中数组是否可以以在数组中的次序为 key

Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 155 (opens in a new tab)

Author 回答者: into-piece (opens in a new tab)

不可,key应为唯一标示,在数组变更时插入或删除后,index无法确保始终指向对应的序列

Author 回答者: Superljf (opens in a new tab)

只要数组次序不变更 是可以用index作为key值的吧