Background: I have an array in data() that gets populated with objects from the backend. If the GET request retrieves 6 objects those 6 objects will update in the array.
Problem: I already understand vm.$set is needed to add properties to an object. But how do add properties to all object in the array?
I want to change:
data() {
return {
expenseButton: [{key:value},{key:value},{key:value}]
};
}
to
data() {
return {
expenseButton: [{key:value, key2:value2},{key:value, key2:value2},{key:value, key2:value2}]
};
}
Failed attempt which logs newValue as a property in the array instead of each object
methods: {
check() {
this.$set(this.expenseButton, "newValue", this.expenseButton.newValue);
console.log(this.expenseButton);
}
},
UPDATE How to target all objects in an array via vm.$set so that all objects has a new property called "newValue"
data() {
return {
expenseButton: [{key1:value1},{key2:value2},{key3:value3}]
};
}
TO
data() {
return {
expenseButton: [{key1:value1,newValue: ''},{key2:value2, newValue: ''},{key3:value3, newValue: ''}]
};
}