[Vuejs]-Vuex store, why adding to array overwrites all values in store with last entry?

3๐Ÿ‘

โœ…

โ€ฆ.hmmmm, well, I think you may be sending the same object, every time

please try this mutation

addToHistory (state: State, someob: any) {
  state.history.push({...someob});
},

or this action

addToHistory(context: ActionContext<State, any>, someob: any) {
  commitAddToHistory(store, {...someob});
}

this, using the spread operator, clones the object. That way every item you add will be new object.

๐Ÿ‘คDaniel

Leave a comment