当前位置: 代码迷 >> 综合 >> Duplicate keys detected: ‘01‘. This may cause an update error
  详细解决方案

Duplicate keys detected: ‘01‘. This may cause an update error

热度:51   发布时间:2023-12-16 04:17:27.0

vue warn
问题:vue 项目报错:key值重复
分析:v-for 循环中绑定的key值有重复的值,导致vue v-for 指令无法正确识别不同的Dom 对象
解决:
1.让后端修改返回的数据(后端返回的数据有问题),每项必须都有一个唯一的code标识,一般下拉框中传给后端的是code,显示的label是名字name
2.v-for 循环时,拼接一个index:key=’item.nam_${index}’ 以形成一个唯一标识,提高dom 渲染的效率

<div 
v-for="(item, index) in list" 
:key="`item.code_${index}`" 
:label="item.name" 
:value="`item.code_${index}`">{
    {
    item.name}}
</div>
  相关解决方案