I have a list of items - each item has an isDefault property. The initial value of item.isDefault is false.
I have a button with a method which toggles 'isDefault' - which should change a css class on the item (A font awesome class. Font awesome css is loaded, and the class works when used on the page as static html).
<div v-for="(item, index) in items">
<button class="button" @click="toggleDefault(index)">
<span class="icon is-small">
<i class="fas" :class="item.isDefault ? 'fa-check' : 'fa-minus' "></i>
</span>
<span>is item default? {{item.isDefault}}</span>
</button>
</div>
My toggleDefault method works - I pass the item index in, and do:
toggleDefault(i) {
this.items[i].isDefault = !this.items[i].isDefault;
}
Indeed, I can see the value change from true to false in dev tools, and the html, and I can log the change to the console...
But the css class doesn't change. Looking through the inspector, it remains 'fa-minus'. I use the same pattern elsewhere and it works? Am I doing something dumb?
** Edit ** Added my JS - isDefault is defined on each item... toggleDefault toggles the value - but the class still doesn't change...
const app = new Vue({
el: '#app',
data: {
items: [
{
name: 'foo',
isDefault: false,
},
{
name: 'bar',
isDefault: false,
}
],
},
methods: {
toggleDefault(i) {
this.items[i].isDefault = !this.items[i].isDefault;
}
}
})
itemsdefined? The only way this can happen is if your item objects don't actually have anisDefaultproperty in their initial data