I have a number of buttons, being generated wuth v-for directive. all of them have initial class, based on the string from an object. I have an event, that is changing this string on button click. But the class is not being updated. What am i doing wrong?
<template>
<v-layout>
<v-btn v-for="cell in cells" :key='cell.id' v-bind:class='cell.color'
v-on:click='click(cell.id)'>
<p v-if="cell.win">win</p>
<p>{{cell.id}}</p>
</v-btn>
</v-layout>
</template>
<script>
export default {
data: () => {
return {
cells: {
},
winId: 0,
}
},
methods: {
generateCells() {
this.winId = Math.floor(Math.random() * 100);
for (var i = 0; i < 100; i++) {
this.cells[i] = {
id: i,
color: 'info'
}
}
},
click(id) {
if (this.cells[id] == this.winId) {
alert('you win');
this.cells[id].color = 'success';
} else {
this.cells[id].color = 'warning';
}
}
},
created() {
this.generateCells();
}
}
</script>
I expect the button class to be updated upon respected object update. The object .color prperty is updated but the class remains initial.