Reputation: 28128
I want to use the index of a v-for
loop as the argument for a click handler, but this returns undefined?
<div v-for="(item, key, index) in groups" v-on:click="selected(index)">{{item.name}}</div>
Handler
selected(i) {
console.log("you clicked " + i) // this logs "you clicked undefined"
}
Upvotes: 2
Views: 1242
Reputation: 82459
Looks like you are using the syntax for objects not arrays. Change your v-for
to:
<div v-for="(item, index) in groups" v-on:click="selected(index)">{{item.name}}</div>
Upvotes: 3