Vue.js 如何配置Vue映射操作

Vue.js 如何配置Vue映射操作,vue.js,vuex,Vue.js,Vuex,vue cli存储 我的代码如下: …映射操作('some/nested/module'[ “getCountry”, “getCurrency” ]), 如何在Vue组件中设置mapActions路径?mapActions用于组件的方法属性 // my-component.vue import { mapActions } from 'vuex' export default { ... methods: { ...mapActions('namespace

vue cli存储

我的代码如下: …映射操作('some/nested/module'[ “getCountry”, “getCurrency” ]),


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

mapActions
用于组件的
方法
属性

// my-component.vue
import { mapActions } from 'vuex'

export default {
    ...
    methods: {
        ...mapActions('namespaced/module', [
            'myAction',
            'myOtherAction'
        ])
    }
}
名称空间可以由模块的文件名确定。例如,给定一个文件-
moduleA.js
-getters,mutations,actions将命名为
moduleA/someGetter
moduleA/someAction
moduleA/someMutation

...mapActions('moduleA', [
    'someAction',
    'anotherAction'
])
注册模块时,其所有getter、action和mutation将根据模块注册的路径自动命名

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

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

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


如何设置名称空间?导出默认的新Vuex.Store({modules:{account:{namespaced:true,modules:{user,set}}})