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