今天学习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

相关文章:

  • 2021-10-07
  • 2021-07-19
  • 2022-12-23
  • 2021-05-26
  • 2021-11-24
  • 2021-05-29
  • 2021-10-26
  • 2021-08-19
猜你喜欢
  • 2021-10-09
  • 2021-05-10
  • 2021-09-25
  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
相关资源
相似解决方案