vuex调用自事件

56 阅读1分钟

使用中的自我总结

在vuex中已有的方法中调用vuex中其他的方法 则要使用this.commit('m_user/saveAddressTostorage') 其中 m_user为方法所在的模块 saveAddressTostorage为方法名

官网内容

Mutation | Vuex (vuejs.org)

你不能直接调用一个 mutation 处理函数。这个选项更像是事件注册:“当触发一个类型为 increment 的 mutation 时,调用此函数。”要唤醒一个 mutation 处理函数,你需要以相应的 type 调用 store.commit 方法:

store.commit('increment')