首页 > 其他 > 详细

Vuex

时间:2019-04-28 17:48:50      阅读:156      评论:0      收藏:0      [点我收藏+]
1 、辅助函数
 
  • mapState

 ...mapState({
    a: state => state.some.nested.module.a,
    b: state => state.some.nested.module.b
  })

简写带空间名称的字符串

...mapState(‘some/nested/module‘, {
    a: state => state.a,
    b: state => state.b
  })
  • mapActions

  ...mapActions([
    some/nested/module/foo, // -> this[‘some/nested/module/foo‘]()
    some/nested/module/bar // -> this[‘some/nested/module/bar‘]()
  ])

简写带空间名称的字符串

 ...mapActions(some/nested/module, [
    foo, // -> this.foo()
    bar // -> this.bar()
  ])

 

  • mapMutations

  • createNamespacedHelpers 

创建基于命名空间的组件绑定辅助函数。其返回一个包含 mapState、mapGetters、mapActions 和 mapMutations 的对象。它们都已经绑定在了给定的命名空间上。
 
更好的写法:
 1 import { createNamespacedHelpers } from vuex
 2 
 3 const { mapState, mapActions } = createNamespacedHelpers(some/nested/module)
 4 
 5 export default {
 6   computed: {
 7     // 在 `some/nested/module` 中查找
 8     ...mapState({
 9       a: state => state.a,
10       b: state => state.b
11     })
12   },
13   methods: {
14     // 在 `some/nested/module` 中查找
15     ...mapActions([
16       foo,
17       bar
18     ])
19   }
20 }

 

 
 

Vuex

原文:https://www.cnblogs.com/it-Ren/p/10785368.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!