Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
haizhilin2013 opened this issue Jun 20, 2019 · 3 comments
Labels
vue vue

Comments

@haizhilin2013
Copy link
Collaborator

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

@haizhilin2013 haizhilin2013 added the vue vue label Jun 20, 2019
@haizhilin2013 haizhilin2013 pinned this issue Jun 26, 2019
@benmo1602
Copy link

benmo1602 commented Jul 1, 2019

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

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

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

@haizhilin2013 haizhilin2013 unpinned this issue Jul 2, 2019
@WenJieLi1998
Copy link

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

@waterkitten
Copy link

waterkitten commented Aug 7, 2020

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
Labels
vue vue
Projects
None yet
Development

No branches or pull requests

4 participants