脚本宝典收集整理的这篇文章主要介绍了Vuex mutitons 和 actions 初使用,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
Vuex 依赖于 Vue 用来管理 Vue 项目状态
状态的修改依赖于 commit
和 dispatch
import Vue from 'Vue';
import Vuex from 'Vuex';
export default new Vuex.Store({
state:{
count:100
},
mutations:{
change(state,payload){
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);
}
}
以上是脚本宝典为你收集整理的Vuex mutitons 和 actions 初使用全部内容,希望文章能够帮你解决Vuex mutitons 和 actions 初使用所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。