zoukankan      html  css  js  c++  java
  • nodejs-- vuex中mapActions

    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 省略....
      })
    }
  • 相关阅读:
    mysql命令行如何得到表结构
    liunx cron问题
    关于SQL判断某个值的查询
    给自己的nexus私人仓库添加缺少的jar包
    MyEclipse9 Maven开发Web工程 详细配置
    springMVC 之 Controller
    java 动态代理
    Freemarker
    java编程陷阱
    HttpClient应用
  • 原文地址:https://www.cnblogs.com/cxiang/p/10528329.html
Copyright © 2011-2022 走看看