error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key

error  Elements in iteration expect to have 'v-bind:key' directives  vue/require-v-for-key

在vue2.2+版本中,当组件使用v-for时,设置v-bind:key是必须的。

可以使用以下几种解决方式:

  • 设置v-bind:key值
  • 如果使用了eslint插件,eslint会对vue进行检查,只需将这个规则屏蔽。
    1. <!--eslint-disable-next-line-->(在想要忽略eslint检查的这行代码前面加上注释)
    2. <!--eslint-disable-->(在整个文件最前面加上注释)
  • 如果使用vscode的vetur插件(但是这个代码报错是esline对vue的检查),则更改vetur配置,vscode->首选项->设置->搜索vetur->将validation.template:true改成false
posted @ 2021-09-22 22:37  慕斯星球  阅读(1453)  评论(0)    收藏  举报