其他分享
首页 > 其他分享> > 报错:Duplicate keys detected: ‘0‘. This may cause an update error. (key值不唯一问题)

报错:Duplicate keys detected: ‘0‘. This may cause an update error. (key值不唯一问题)

作者:互联网

报错信息如下:

在这里插入图片描述

原代码:

<span v-for="(item,index) in blankTitle" :key="index">
    <span>{{item}}</span>
</span>
<span v-for="(resultItem,resultIndex) in resultData" :key="resultIndex">
    <span>{{resultItem}}</span>
</span>

如此会造成key值不唯一。

修改后代码:

<span v-for="(item,index) in blankTitle" :key="index">
    <span>{{item}}</span>
</span>
<span v-for="(resultItem,resultIndex) in resultData" :key="resultIndex+100">
    <span>{{resultItem}}</span>
</span>

根据情况将两个key值加以区分即可。

标签:keys,Duplicate,item,detected,报错,key,原代码,resultItem
来源: https://blog.csdn.net/elephant_my/article/details/114692569