Answer the question
In order to leave comments, you need to log in
How to properly update nested object?
Hello.
vuex has an object:
store: {
product: {
name: 'Product',
options: {
isFree: false,
delivery: true
}
}
}
updateProduct(state, {product, data}) {
Object.assign(product, data)
}
const product = this.product
this.$store.commit('updateProduct', {
product,
data: {
options: {
isFree: true,
}
}
}
Answer the question
In order to leave comments, you need to log in
Pass not the entire object to the mutation, but only the part of it that you are going to update:
this.$store.commit('updateProduct', {
product: product.options,
data: {
isFree: true,
},
});
Isn't it possible to write a mutation to change an option and call it when needed?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question