Skip to content

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

Open
@haizhilin2013

Description

@haizhilin2013
Collaborator

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

Activity

wenyejie

wenyejie commented on Jun 21, 2019

@wenyejie

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

waterkitten

waterkitten commented on Aug 7, 2020

@waterkitten
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 的状态
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @wenyejie@haizhilin2013@waterkitten

        Issue actions

          [vue] vuex的state、getter、mutation、action、module特性分别是什么? · Issue #388 · haizlin/fe-interview