1、Vuex是中心状态管理方案,Vuex里面的store相当于一个仓库,用来存储数据的。
2、const store = new Vuex.Store({
state:{}, //调用 this.
store.commit(“方法名”,参数) 同步调用
getters:{}, //this.
store.dispatch(“方法名”,参数) 异步调用
})
3、给对象添加新属性
Vue.set(obj,‘newprop’,123)
state.obj ={…state.obj,newprop:123}
4、只要store.state里面的值发生改变,就会立即触发更新相关联的dom,也会重新计算store.getters
5、使用mapState
import {mapState} from ‘vuex’
export default{
computed:mapState({
count:state=>state.count,
countAlias:‘count’ //state=>state.count
})
}
调用方法:this.count()相当于this.
store.commit()
7、分发action 使用store.dispatch
action提交给mutation,mutation更改state值
Vuex的基本方法
猜你喜欢
转载自blog.csdn.net/qq_39039128/article/details/83067844
今日推荐
周排行