Dmitry Chernikov
Dmitry Chernikov

Reputation: 123

Newly added array objects works the same

Please help. I have this code. I have a feeling that v-for caches (or wrongly work with it) my data array. Newly added objects (with "Add" button) are edited like the same. Try to add some rows and put some text or change a checkbox and you will see.

Upvotes: 0

Views: 35

Answers (1)

Shivam Singh
Shivam Singh

Reputation: 1731

// Update this fn to: 
addMessenger() {
            this.data.profile.vsAppMessengers.push({...this.data.profile.messengerTemplate}); 
},

Issue was: the object is copied by reference. To read more: https://codeburst.io/explaining-value-vs-reference-in-javascript-647a975e12a0

Updated fiddle link: https://jsfiddle.net/shivampesitbng/6hoL0jts/2/

Upvotes: 2

Related Questions