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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM