In my component I have:
currentItem.recipe
currentItem is a state in vuex initiated as object:
currentItem: {}
In the same component I import it with mapState:
...mapState('ItemStore', [
'currentItem'
])
When I add a recipe for it, this mutation gets called:
ADD_ITEM_RECIPE: (state, recipe) => {
state.currentItem.recipe = recipe
}
recipe
is response from server to a post request to create a new recipe.
In my component I have some v-if="currentItem.recipe"
, which is false at the beginning as currentItem
has no recipe
The mutation get executed, in devtools I can see recipe
being added to currentItem
. But component does not update. The v-if
does not change to true. In devtools, if I commit the mutation manually it works as expected.
So I tried to change the mutation to:
state.currentItem.recipe = Object.assign({}, state.currentItem.recipe, recipe)
but the problerm is still there.
Why is this happening and how can I solve it?