我是 vueJs 的新手,一旦您单击它,我就会尝试将“活动”类切换为单个元素。这是我的代码,使用类 material_icons 切换所有元素。如何仅切换单击的元素?谢谢。我的 hmtl :
<div v-for="(listArtist, index) in listArtists" class="col s4 center" id="art">
<p> {{ listArtist.title_short }}</p>
<p>{{ listArtist.artist.name }} </p>
<p>{{ listArtist.album.title }}</p>
<div id="margin-test">
<i class="material-icons" @click="fav(listArtist.title,listArtist.album.title,listArtist.artist.name,listArtist.id)" v-bind:class="{'active': color}">favorite_border</i>
</div>
我的js:
data: {
listArtists:[],
color: false,
}
fav: function(titleTrack, album, artist, id ){
this.color = !this.color
}