Vuex mutitons和actions初使用详解

2020-06-13 10:36:35易采站长站整理

state.count += payload;
}
},
actions:{
change(context,palyload){
context.commit('change',palyload);// 异步触发 mutaiton
}
},
getters:{
getCount(){
return state.count;
}
}
})


{{$store.state.count}}
<button @click="commitChange">更改count</button>
<button @click="dispatchChange">更改count</button>

...

methods:{
commitChange(){
this.$store.commit('change',1);
},
dispatchChange(){
this.$sotre.dispatch('change',10);
}
}