<div class="topleft01" v-for="value in 6" :key="value" @click="leftTitleClick(value-1)" >
</div>
添加点击事件的时候怎么给循环里面单独添加
<div class="topleft01" v-for="value in 6" :key="value" @click="leftTitleClick(value-1)" :ref="'xxx'+value" >
</div>
js
leftTitleClick(value){
this.$refs.xxx//这样就能获取到v-for中的某一个
}
谢谢
<div id="myDiv">
<div class="top-left" v-for="(value,index) in list" :key="index" @click="HandleClick(index)" >{{value}}</div>
</div>
<script>
var vm = new Vue({
el:'#myDiv',
data(){
return{
list:[1,2,3,4,5,6]
}
},
methods:{
HandleClick(index){
//点击事件
switch(index){
case 0: console.log(index);
break;
}
//修改对应数组值
const { list } = this;
list[index] +=1;
}
}
})
</script>
谢谢