I am making copy of vuex state. That array structure is like this:
export const store = new Vuex.Store({
state: {
contacts: [
{
id: 122345,
name: "Marko Marki",
email: "marko@marko.com",
phones: ["478 8273", "787 7671"],
avatar: "https://avatars0.githubusercontent.com/u/9064066?v=4&s=460"
},
{
id: 122346,
name: "Ivan Ivandi",
email: "ivan@ivan.com",
phones: ["787 7671"],
avatar: "https://avatars0.githubusercontent.com/u/9064066?v=4&s=460"
},
I am making copy of this state to pass it to my edit component to work with like this:
getContactsCopy(state) {
const copyContacts = state.contacts.map(contact => ({...contact}))
console.log(copyContacts)
return copyContacts
}
...and back in my edit component I am getting this copyContacts data as expected, but for phone numbers in phones array I still have reference to original state which is not what I want, for all other properties like name, email and so on I have copy and on canceling the edit mode original state stays as it was except phone numbers. How can I make copy of my every object property including that phones array?