如图,渲染出来的列表点击的时候需要单独给li添加一个class,但是我用v-bind:class的时候会导致全部li都被添加,如何设置data才能够让点击那个li单独添加class?
-
{{ choice.item }}
var vq = new Vue({
el: '.secondScene',
data: {
title: qdata[rnum].title,
choices: qdata[rnum].content,
ison:false
},
methods: {
next: function($index) {
this.ison = true;
}
}
})
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
data中创建一个属性i。
li注册一个click事件并把$index的值传进去,在这个事件中把i赋值为$index。
然后li的v-bind:class="{classname: i==$index}"