vue中提示$index is not defined

今天学习Vue中遇到了一个报错信息:$index is not defined,是我写了个for循环在HTML中,然后是因为版本的问题

下面是解决方法:

原来的是 v-for="person  in  items"    

 

 

v-on:click="deletePerson($index)"//这个仅仅适用于1.0版本,不要采坑了同学们

 

 

这个在Vue1.0版本中式适用的可以直接使用$index,但是在2.0是不适合的

在Vue 2.0版本中获取索引我们需要通过 v-for = "(person ,index)  in items ",  点击事件我们也不能使用$index,应该使用

 

v-on:click="deletePerson(index)"

 

 

https://blog.csdn.net/shaleilei/article/details/79145593

 
 
https://segmentfault.com/q/1010000007648587

posted on 2018-06-15 13:03  隨風.NET  阅读(386)  评论(0编辑  收藏  举报

导航