Fe-interview: [vue] vuex的state、getter、mutation、action、module特性分别是什么?

Created on 20 Jun 2019  ·  2Comments  ·  Source: haizlin/fe-interview

[vue] vuex的state、getter、mutation、action、module特性分别是什么?

vue

Most helpful comment

state, 状态初始化, 并实施观察
getter, 获取数据用于view或data中使用
mutation: 内部处理state变化
action: 处理外部交互
module: 模块化以上四个

All 2 comments

state, 状态初始化, 并实施观察
getter, 获取数据用于view或data中使用
mutation: 内部处理state变化
action: 处理外部交互
module: 模块化以上四个

const moduleA = {
  state: () => ({ ... }),
  mutations: { ... },
  actions: { ... },
  getters: { ... }
}

const moduleB = {
  state: () => ({ ... }),
  mutations: { ... },
  actions: { ... }
}

const store = new Vuex.Store({
  modules: {
    a: moduleA,
    b: moduleB
  }
})

store.state.a // -> moduleA 的状态
store.state.b // -> moduleB 的状态
Was this page helpful?
0 / 5 - 0 ratings