<i :class="{"iconfont":true,"icon-shoucangxing":true,"shoucang":true,"active":isSelected}" @click="toggleCollect"></i>
isSelected:false
toggleCollect(){
this.isSelected = !this.isSelected
}
css:
.shoucang{
font-size: 32px;
}
.shoucang.active{
color: red;
}
because the button has fixed class,iconfont, icon-shoucangxing and shoucang, when we click, we only need to switch active, while the other class is fixed. I have implemented it in accordance with the above method, and I have succeeded. I think there should be a simple way. I hope you can share the following.