1π
β
The issue here is reactivity. You canβt just add arbitrary properties to objects without using Vue.set
or they wonβt be reactive:
Your loop needs to use Vue.set()
:
for(let i = 0; i < this.cards.length; i++) {
Vue.set(this.edit, this.cards[i]._id, false)
}
And your click
methods needs to use Vue.set()
methods: {
editCard(card) {
Vue.set(this.edit, card._id, true)
},
saveEdit(card) {
Vue.set(this.edit, card._id, false)
}
}
You may also use this.$set
within components as well.
π€Ohgodwhy
0π
You need to use Vue.$set to check changes inside your object:
mounted() {
if(this.cards.length > 0) {
this.edit = {};
for(let i = 0; i < this.cards.length; i++) {
this.$set(this.edit, this.cards[i]._id, false )
}
}
},
methods: {
editCard(card) {
//this.edit[card._id] = true;
this.$set(this.edit, card._id , true )
console.log(this.edit[card._id]);
console.log(this.edit);
},
saveEdit(card) {
//this.edit[card._id] = false;
this.$set(this.edit, card._id , false )
console.log(this.edit[card._id]);
console.log(this.edit);
}
}
π€Hans Felix Ramos
Source:stackexchange.com