动态添加class的关键是判断条件,
点击某个item时设置isAdd为当前索引,
以使得index == isAdd为true,
就能成功添加class到我们点击的item上
<p v-for="(sel, index) in selection"
:key="index"
:class="{ tavActive:index == isAdd}"
@click="tabCheck(index)">{{sel}}
</p>
export default {
name: "details",
data(){
return{
selection:["详情", '选集'],
isAdd:''
}
},
methods:{
tabCheck(index){
if(this.selection[index]){
this.isAdd = index;
}
}
}
}
转载自:https://blog.csdn.net/qq_39905409/article/details/90450585