Vue报错 Duplicate keys detected: 'Deshun'. This may cause an update error的问题解决

Vue 项目中,在使用 v-for 列表循环时报错:Duplicate keys detected: '81bc03e2903447d8bb23fe18677abe54'. This may cause an update error. 

虽然不影响页面的正常显示,但是这么一长串的 console 报错肯定是要解决的。

看一下代码:

<view
  v-for="item in shareCount"
  :key="item.userId"
>
  ...
</view>

出现这种问题,应该是 v-for 循环里的 key 值重复了,把 key 值改为 index 就不会报错了。

<view
  v-for="(item, index) in shareCount"
  :key="index"
>
  ...
</view>

不过使用 index 会影响性能,看是不是存在别的问题。

在请求接口后,使用了 concat() 方法,并重新赋值了,问题是出在这了。

that.shareCount = that.shareCount.concat(count)

改成下面的代码就可以了:

that.shareCount.push(...count)


未经允许不得转载:Web前端开发资源网 » Vue报错 Duplicate keys detected: 'Deshun'. This may cause an update error的问题解决

推荐阅读:

jQuery实现本地input选择图片实时显示

html CSS引用字体文件

解决老版本IE不兼容rgba的问题

IE版本判断代码 if IE 6

overflow的一些小细节笔记

赞 (1)
分享到: +

评论 沙发

Avatar

换个身份

  • 昵称 (必填)
  • 邮箱 (选填)