大概的代码,简而言之就是一个收藏按钮状态切换
<span
class="icon-star"
:class='{ "active" : result.isCollection==true}'
@click="collectionHandler(result.isCollection)"
>
</span>
collectionHandler(isCollection) {
this.$set(this.result, 'isCollection', !isCollection)
console.log(this.result.isCollection)
}
通过控制台可以判断当前 result.isCollection
的值是根据点击在动态变化的,但是:class绑定的类并没有动态添加,想问是什么原因?