代码之家  ›  专栏  ›  技术社区  ›  bin ye

如何配置Vue映射操作

  •  2
  • bin ye  · 技术社区  · 7 年前

    vue cli存储

    我的代码如下: 。。。mapActions('部分/嵌套/模块'[ “getCountry”, '获取货币' ]),则,

    enter image description here

    如何在Vue组件中设置mapActions路径?

    1 回复  |  直到 7 年前
        1
  •  5
  •   Brian Lee    7 年前

    mapActions 用于组件的 methods 所有物

    // my-component.vue
    import { mapActions } from 'vuex'
    
    export default {
        ...
        methods: {
            ...mapActions('namespaced/module', [
                'myAction',
                'myOtherAction'
            ])
        }
    }
    

    名称空间可以由模块的文件名确定。例如,给定一个文件- moduleA.js -getter、突变和操作的名称空间为 moduleA/someGetter ,则, moduleA/someAction ,则, moduleA/someMutation

    ...mapActions('moduleA', [
        'someAction',
        'anotherAction'
    ])
    

    注册模块时,其所有getter、action和translation将根据模块注册的路径自动命名

    另一种方法是使用 registerModule 方法,该方法允许动态运行时注册:

    // register a module `myModule`
    store.registerModule('myModule', {
      // ...
    })
    
    // register a nested module `nested/myModule`
    store.registerModule(['nested', 'myModule'], {
      // ...
    })
    

    Vuex Docs - Namespacing

    Vuex Docs - Dynamic Module Registration