解决vue报错Duplicate keys detected: ‘9‘. This may cause an update error.

Duplicate keys detected: ‘9’. This may cause an update error.是vue发现key不是唯一的而引发的错误.

译为中文大概是 : 检测到重复键 : '9’可能会导致一个更新错误.
在这里插入图片描述
查找问题 找到我们报错的组件=>
1,查看循环项绑定的key得知了问题所在
在这里插入图片描述
2,查看定义的数据,由图可知,因为集合中的id有重复的值,当我们在 v-for 中使用id作为key时,即为报错
在这里插入图片描述
解决办法

<div class="list" v-for="(item,index) in list" :key="index">

猜你喜欢

转载自blog.csdn.net/weixin_44248187/article/details/124055420
今日推荐