Vue2 + Vuex Commit Not Committing (without Vue devtools)

帅比萌擦擦* 提交于 2019-12-06 14:29:36

You fell into the object reference trap. The quote is an object, which is passed to the action as the payload. When you commit that payload, it safes the reference into your state.

Now both the component and the store point to the same object.

The solution is to copy the input into a new object, either with the spread operator or Object.assign

Its generally a good practice to always copy the payload in mutators (if it is an object)

function(state, payload){
  Vue.set(state.quotes, payload.id, {... payload });
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!