vuex中如何区分及使用 this.$store.dispatch() 和 this.$store.commit()

this.$store.dispatch() 和 this.$store.commit()的本质是存取方式的不同,两个方法都是传值给vuex的mutation改变state

commit: 同步操作

存值 this.$store.commit(‘state变量/state方法返回的值’,name)

取值 this.$store.state.changeValue

dispatch: 异步操作

存值 this.$store.dispatch(‘state变量/state方法返回的值’,name)

取值 this.$store.getters.getlists

demo示例可以查看如下参考文献

demo示例参考

vuex详解参考文献如下

vuex运行原理详解

官方详解

发表评论 / Comment

用心评论~