Javascript Vue vor循环索引为单击函数参数

Javascript Vue vor循环索引为单击函数参数,javascript,vue.js,vuejs2,Javascript,Vue.js,Vuejs2,我想使用v-for循环的索引作为单击处理程序的参数,但这会返回未定义的 <div v-for="(item, key, index) in groups" v-on:click="selected(index)">{{item.name}}</div> 看起来您使用的是对象而不是数组的语法。将您的v-for更改为: <div v-for="(item, index) in groups" v-on:click="selected(index)">{{item

我想使用
v-for
循环的索引作为单击处理程序的参数,但这会返回未定义的

<div v-for="(item, key, index) in groups" v-on:click="selected(index)">{{item.name}}</div>

看起来您使用的是对象而不是数组的语法。将您的
v-for
更改为:

<div v-for="(item, index) in groups" v-on:click="selected(index)">{{item.name}}</div>
{{item.name}

看起来您使用的是对象而不是数组的语法。将您的
v-for
更改为:

<div v-for="(item, index) in groups" v-on:click="selected(index)">{{item.name}}</div>
{{item.name}

组是数组还是对象?组是数组还是对象?谢谢,我没有意识到有区别…:)谢谢,我不知道有什么不同…:)