vue 报错:Elements in iteration expect to have ‘v-bind:key‘ directives
Vue2.0不同于Vue1.0版本,它把$index和$key都移除了,取而代之的是:key属性。
如果还像之前那样写的话会报Property or method "$index" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.之类的错误。
Vue1.0版本的写法为:
<ul id="example">
<li v-for="item in items">
{{$index}}
{{$key}}
</li>
</ul>
Vue2.0版本的写法为:
<ul id="example">
<li v-for="(item,index) in items" :key="item.index">
{{item}}
{{index}}
</li>
</ul>
另一个办法是在build处关闭eslint检测(没试过)
...(config.dev.useEslint ? [createLintingRule()] : []),