- this.$store.commit()
commit: 同步操作
this.$store.commit('方法名',值) //存储
this.$store.state.方法名 //取值
- this.$store.dispatch()
dispatch: 异步操作
this.$store.dispatch('方法名',值) // 存储
this.$store.getters.方法名 // 取值
当操作行为中含有异步操作:
比如向后台发送请求获取数据,就需要使用action的dispatch去完成了。
其他使用commit即可。
其他了解:commit=>mutations,用来触发同步操作的方法。
dispatch =>actions,用来触发异步操作的方法。
在store中注册了mutation和action,在组件中用dispatch调用action,然后action用commit调用mutation,
其他参考:https://blog.csdn.net/wsjzzcbq/article/details/123003859