I am having this issue with Vuex:
I am trying to mutate a nested object in my module state. When I do the mutation it sets the value in all the objects nested properties in my module state.
I dynamically set the collection objects. My module state:
collection: [{
id: 1,
prop: {
nestedProp: ""
}
},
{
id: 2,
prop: {
nestedProp: ""
},
},
]
When I properly mutate the state in the mutations methods, it duplicates the value:
changeValueById(state) {
const obj = state.collection.find(obj => obj.id === 1)
obj.prop.nestedProp = "new value!!"
}
The espected value:
// colletion[0].prop.nestedProp === "new value!!"
// colletion[1].prop.nestedProp === ""
// colletion[2].prop.nestedProp === ""
But I get:
// colletion[0].prop.nestedProp === "new value!!"
// colletion[1].prop.nestedProp === "new value!!" (duplicated)
// colletion[2].prop.nestedProp === "new value!!" (duplicated)
Am I mutating the state in the wrong way? I can't understand why it is duplicating the value y the whole state tree.