https://vuex.vuejs.org/zh-cn/api.html

命令

用途

备注

this.$store

组件中访问store实例

 

store.state.a

获取在state对象中的数据

store文件中

$store.state.a

视图上(即标签上)

 

 

this.$store.state.a

1) 组件内部,data数据里边

2) 组件计算属性返回值

computed: { 

   count () { return this.$store.state.count }

 }

 

store.getters

派生state的一些状态(即拿到,再进行一些小变化后返回新的状态,比如给state中某个数组内部小于10的前边加上0再返回)

Getter对象

this.$store.getters.oneFunction

访问Getter对象内的某个属性的值

在组件的计算属性中使用

store.commit()

【方法】提交 mutation,触发状态变更(修改state的值)

action文件中

this.$store.commit(state,payload)

在组件的 methods 中

store.dispatch()

【方法】触发 action,以间接地触发mutation,进而使状态变更(修改state的值)

action文件中

 

this.$store.dispatch('incrementBy',amount)

在组件的 methods 中

'incrementBy':  mutationFunctionName

amount =  payload

 

2018-04-07  18:00:52

相关文章:

  • 2021-10-21
  • 2022-01-08
  • 2021-04-24
  • 2021-10-16
  • 2021-10-05
猜你喜欢
  • 2022-12-23
  • 2023-01-31
  • 2021-08-01
  • 2021-09-18
  • 2022-01-12
  • 2021-12-05
  • 2021-11-22
相关资源
相似解决方案