智能营销总部:vuex总结

定义
1、vue全局状态管理器
2、实现组件之间跨层传递数据,实现数据与视图响应式更新

参数
state 状态数据
用法:
this.$store.state.xxx
…mapState([xxx,yyy])
相当于vue里面的data

getters 获取
用法:
this.$store.getters .xxx
…mapGetters ([xxx,yyy])
相当于vue里面的computed

mutations 方法
用法:
this.$store.commit.xxx
…mapMutations ([xxx,yyy])
相当于vue里面的methods

actions 动作
用法:
this.$store.dispatch.xxx
…mapActions ([xxx,yyy])
相当于vue里面的methods(异步的)

模块
意义:vuex允许我们将store分割成模块(module)
每个模块都拥有:
state、mutations、actions、getters
1、state:
默认带命名空间login
$.store.state.login.age
2、mutations:
默认不带命名空间
$store.commit(xxx)
3、actions:
默认不带命名空间
store.dispatch(xxx)context(第一参数):commit、getters、dispatch、rootState(全局state)、rootGetters(全局的getters)4、getters:默认不带命名空间访问:store.dispatch(xxx)context(第一参数):commit、getters、dispatch、rootState(全局state)、rootGetters(全局的getters)4、getters:默认不带命名空间访问:store.dispatch(xxx)context(第一参数):commit、getters、dispatch、rootState(全局state)、rootGetters(全局的getters)4、getters:默认不带命名空间访问:store.getters.xxx
state模块的state
全局的getters(包括模块getters)
rooterState全局的state

智能营销总部官网 智能营销官网 ;智能营销官网

猜你喜欢

转载自www.cnblogs.com/SC123321/p/13386119.html
今日推荐