I am working with an Array to fill a Dialog Vue Component. My setup looks like this:
basicInfo: [{ firstName: "John" , lastName: "Doe" }],
<basicInfoForm v-model="showBasicInfoForm" :basicInfo="newbasicInfo[0]"></basicInfoForm>
In the Parent component, I have
{{basicInfo[0].firstName + ' ' + basicInfo[0].lastName}}
There is a button that triggers a Form Component within a Dialog popup for editing. The issue I am facing is that any changes made in the Dialog reflect immediately on the Parent as well. I want to include a cancel button in the Child Dialog so changes can be reverted. To achieve this, I cloned the array before passing it:
this.newbasicInfo = this.basicInfo.slice();
And in the Child Dialog component,
<v-text-field
v-model="basicInfo.firstName"
label="First Name"
class="input-name styled-input"
></v-text-field>
props: {
value: Boolean,
basicInfo: Array
},
The concern here is that every keystroke updates both the basicInfo array and the newbasicInfo array simultaneously, making it impossible to revert back to the original data if a cancel action is taken. As a beginner in Vue and Components, I might have misconfigured something. What could be causing changes to occur in both arrays at the same time?