vue 报错:Elements in iteration expect to have ‘v-bind:key‘ directives.eslint-plugin-vue

原因:

在用vscode 编写vue 代码时,因为安装的有vetur 插件,所以当代码中有v-for 语法时,会提示,“Elements in iteration expect to have ‘v-bind:key’ directives.eslint-plugin-vue” 这个错误。这是eslint 的功能,对vue 进行了eslint 检查。

解决:

  • 第一种方法,添加 :key 属性

    在v-for 指令后加上:key=“value”

  • 第二种方法,修改vetur 配置

    路径:vscode -> File -> Preferences -> Settings
    搜索:vetur.validation.template
    取消勾选

你可能感兴趣的:(vue.js,javascript,前端)