Answer the question
In order to leave comments, you need to log in
How to get index from list in VUE?
<template>
<div>
<hr>
<h1>{{ text }}</h1>
<br>
<ul v-model="list" :key="index">
<li v-for="(item, index) in list" @click="testA" class="list btn">
{{ index }} {{ item.name }}
</li>
</ul>
</div>
</template>
<script>
export default {
name: 'test',
data(){
return{
text: "Текст",
list: [
{ name: 'Petya'},
{ name: 'Vasia'},
{ name: 'Gosha'},
]
}
},
methods: {
testA(){
alert(this.index)
console.log(this)
// alert(this.list[this.index].name)
}
}
}
</script>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question