Log

在使用Vue做表单时发生如下错误:

[Vue warn]: Duplicate value found in v-for="data in content": "". Use track-by="$index" if you are expecting duplicate values. (found in component: <grid>)

问题原因

由于我的JSON数组中有多个相同的字符串,类似下面这样:

{"arr01":["","","","",""],
 "arr02":["","","","",""],
 "arr03":["","","","",""]}

这是我从服务器拿到的原始数据,它出现了N多的空字符串。

解决方法

其实在log中已经提到了,我查询了Vue官网之后找到了解决方法:
就是在v-for后面加上track-by="$index"的属性即可。

<tr v-for="data in content" track-by="$index">

具体说明可以参考官方资料#track-by $index

Logo

前往低代码交流专区

更多推荐