记录错误:Custom elements in iteratio
2020-06-07 本文已影响0人
长鲸向南
报错代码:Custom elements in iteration require 'v-bind:key' directives
设置key
在使用vue-cli工具开发时,使用v-for出现以下报错
![](https://img.haomeiwen.com/i12926249/20e5a31854dc710b.jpg)
原因是vue在升级到2.2后,当在组件中使用 v-for
时,规定必须有设置 key
.
<swiper>
<swiper-item v-for="(item,index) in bannes" :key="index"></swiper-item>
</swiper>
关闭Eslint代码检查
还有一个原因就是使用了Vetur插件,然后Eslint对vue进行了检查,因为在vue2.2.0+的版本中,使用v-for时,key是必须的
解决办法是:关闭eslint对该插件的检查
文件 -> 首选项 -> 设置,搜索vetur.validation.template,把勾选取消掉
![](https://img.haomeiwen.com/i12926249/4033f635fcd014f2.jpg)
这样子问题就解决了。