My code has a feature where item.fav starts as false, but changes to true when a button is clicked. I want the color of the icon to turn purple when item.fav is true, but it's not working as expected.
<template>
<v-container fluid>
<v-row>
<v-col v-for="(item, index) in items">
<v-btn icon @click='changeFav(item)'>
<v-icon :style='{color:`${fillcolor(item)}`}'>mdi-heart</v-icon>
</v-btn>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
....,
methods: {
fillcolor(item){
return item.fav ? 'purple' : 'orange';
},
changeFav(item){
item.fav=true;
},
}
</script>
I also attempted to use a class
.....
<v-icon class='{fillColor: item.fav}'>mdi-heart</v-icon>
.....
<style>
.fillColor {
color: 'purple';
}
</style>
Using a data variable as the condition works, but I can't do that in this loop. What am I doing wrong here or how can I do it better?