vue使用v-for时vscode报错 Elements in iteration expect to have 'v-bind:key' directives

vue使用v-for时vscode报错 Elements in iteration expect to have 'v-bind:key' directives

Vue 2.2.0+的版本里,当在组件中使用v-for时,key是必须的
错误提示:
[vue-language-server] Elements in iteration expect to have 'v-bind:key' directives.
Renders the element or template block multiple times based on the source data
原因是eslint检测出现bug
---------------------
解决方法:
1.在v-for 后添加 :key='item'
<li v-for="i in list" :key="i">

<div class="item" v-for="(user,index) in datalist" :key='index' >

2.在build处关闭eslint检测
...(config.dev.useEslint ? [createLintingRule()] : []),

3.更改vetur配置 vscode->首选项->设置->搜索(vetur)
"vetur.validation.template": true,
改成:false

posted @ 2019-03-03 18:53  大自然的流风  阅读(28839)  评论(0编辑  收藏  举报