I have a form that has a modal that I use to populate an array within the form. Every time the modal is submitted, I push the Vue object into an array that is on the main form. The problem I'm facing is that every item in the array is linked and when I edit one item, all the items in the array get edited.
data: {
myForm: {
form_element: null,
my_array: [],
},
modalForm: {
modalFormElement: null,
},
},
methods: {
addRow(){
this.myForm.my_array.push(this.modalForm);
},
},
Assigning this.modalForm to a variable first did not work.
this.myForm.my_array.push([...this.modalForm])this.modalFormbefore you push it to the array so that you are not storing the same object in the array multiple times. Maybe a deep clone.{...this.modalForm}