<div v-for="(n, index) in items" :id="n" @click="myMethod($event)">{{n}}</div>
The array contains various animals such as mouse, bull, tiger, rabbit, pig, cat, dog, and horse.
In the method below, we are logging the id of the clicked element:
myMethod: function(event){
console.log(event.target.id);
}
While binding the content to the id of each div helps identify which item was clicked, accessing the index of the items within myMethod()
is proving challenging. However, there’s a need to utilize the index for additional tasks. How can this issue be resolved?