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