首页 > Web开发 > 详细

nodejs-- vuex中mapActions

时间:2019-03-14 10:05:23      阅读:169      评论:0      收藏:0      [点我收藏+]

mapActions() 返回的是一个对象, 用了 ... 扩展符后,才可以放进一个对象里,和其他组件内定义的 method 在同一个 methods 对象。

 

 

{
methods: mapActions() // 如果没有其它组件内的定义的方法,可以这样写
}
{
methods: {
...mapActions(),// 如果有其他定义的方法
otherMethod1 () {},
otherMethod2 () {}
}

 

 

 


}

假设mapActions(),返回的是

 
{
    a() {},
    b() {}
}

那 ...mapActions(),只不过是把a,b都拿出来跟其他方法放在一起了而已。
...代表两种意思,一种是剩余操作符,一种是扩展运算符,你题目里用的那个应该是剩余操作的意思,而...mapActions才是扩展运算符。

 

 

其中参数的使用方法原理为::

 

 

methods: {
  ‘some/nested/module/foo‘: (val) {
    return this.$store.dispatch(‘some/nested/module/foo‘, val))
  }
}

但这个Mutations这么长, 一般不会这样去转换,会加个别名

 
methods: {
  ...mapActions({
    foo: ‘some/nested/module/foo‘,
    bar: ‘some/nested/module/bar‘
  })
}

//相当于下面的写法

methods: {
  foo(val){
    return this.$store.dispatch(‘some/nested/module/foo‘, val))
  }
   //bar 省略....
  })
}

nodejs-- vuex中mapActions

原文:https://www.cnblogs.com/cxiang/p/10528329.html

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