I'm feeling really confused at the moment. I have a list of items, each with a heart-shaped "like" button. When I click on the icon, I want the color to change. However, the issue is that all the hearts change color instead of just the one I clicked on. Should I include an argument in the markAsFavorite
method, such as index or book?
<template>
<v-flex v-for="(book, index) in allBooks">
<div>Title: {{ book.title }}</div>
<i @click="markAsFavorite(index)" :class="{isActive: isActive(index)}" class="fas fa-heart"></i>
</template
<script>
name: 'Books',
data () {
return {
allBooks: [
{ title: "one" },
{ title: "two" },
{ title: "three" },
{ title: "four" },
],
activeHeartIndex: -1,
}
},
methods: {
markAsFavorite(index) {
this.activeHeartIndex = index;
},
isActive(index) {
return this.activeHeartIndex === index;
}
}
</script>