一、相同
都可以用于存取值
this.$store.commit('key',val)【存值】
this.$store.state.key【取值】
例:
存:
findAllMenuTree().then((res)=>{
if(res.code == 200){
this.$store.commit("setMenu", {
menuData: res.result
});
}})
取:
this.$store.state.menuData;

this.$store.dispatch('key',val)【存值】
this.$store.getters.key【取值】
二、不同
commit:同步操作,写法:this.$store.commit(‘mutations方法名’,值)
dispatch:异步操作,写法:this.$store.dispatch(‘actions方法名’,值)
在store中定义了mutations和actions

本文详细介绍了Vue框架中状态管理工具Vuex的使用方法,包括如何通过commit和dispatch进行值的存取操作。同时对比了两者之间的区别,如commit为同步操作,而dispatch则适用于异步操作。
1244

被折叠的 条评论
为什么被折叠?



