Skip to content

[vue] vuex的store有几个属性值?分别讲讲它们的作用是什么? #387

Open
@haizhilin2013

Description

@haizhilin2013
Collaborator

[vue] vuex的store有几个属性值?分别讲讲它们的作用是什么?

Activity

benmo1602

benmo1602 commented on Jul 1, 2019

@benmo1602

https://vuex.vuejs.org/zh/

state:存贮公共数据的地方
Getters:获取公共数据的地方
mutations:放的是同步的操作和reducer有点像 通过store的commit方法来让mutations执行
action:放的是异步的操作 通过dispatch的方法让action里面的方法执行
context是store的一个副本

Vuex就是提供一个仓库,store仓库里面放了很多对象其中state即使数据源存放地,

unpinned this issue on Jul 2, 2019
WenJieLi1998

WenJieLi1998 commented on Apr 17, 2020

@WenJieLi1998

state:存放公共数据的地方
getter:获取根据业务场景处理返回的数据
mutations:唯一修改state的方法,修改过程是同步的
action:异步处理,通过分发操作触发mutation
module:将store模块分割,减少代码臃肿

waterkitten

waterkitten commented on Aug 7, 2020

@waterkitten

https://blog.csdn.net/szuwaterbrother/article/details/10622307
image

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

        @haizhilin2013@benmo1602@WenJieLi1998@waterkitten

        Issue actions

          [vue] vuex的store有几个属性值?分别讲讲它们的作用是什么? · Issue #387 · haizlin/fe-interview