1. 程式人生 > >vue中提示$index is not defined

vue中提示$index is not defined

pid defined AC 信息 AI 直接 otto 通過 sdn

今天學習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

vue中提示$index is not defined