Situation: In my data(), I have an array that receives objects from the backend. When the GET request brings back 6 objects, those objects are updated in the array.
Issue: I am aware that vm.$set is necessary to add properties to an object. But how can I add properties to all objects in the array?
I aim to modify:
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}]
};
}
Attempted Solution resulted in newValue being added as a property in the entire array rather than each object
methods: {
check() {
this.$set(this.expenseButton, "newValue", this.expenseButton.newValue);
console.log(this.expenseButton);
}
},
UPDATE How can I apply vm.$set to target all objects in an array so that each object has a new property named "newValue"?
data() {
return {
expenseButton: [{key1:value1},{key2:value2},{key3:value3}]
};
}
TO
data() {
return {
expenseButton: [{key1:value1,newValue: ''},{key2:value2, newValue: ''},{key3:value3, newValue: ''}]
};
}