<>定义
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:
默认不带命名空间
s t o r e . d i s p a t c h ( x x x ) c o n t e x t ( 第 一 参 数 ) : c o m m i t
、 g e t t e r s 、 d i s p a t c h 、 r o o t S t a t e ( 全 局 s t a t e ) 、 r o o
t G e t t e r s ( 全 局 的 g e t t e r s ) 4 、 g e t t e r s : 默 认 不 带 命 名 空 间 访 问
: 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
<>命名空间
今日推荐