【发布时间】:2018-03-29 05:32:57
【问题描述】:
【问题讨论】:
【问题讨论】:
mapActions 用于组件的methods 属性中。
// my-component.vue
import { mapActions } from 'vuex'
export default {
...
methods: {
...mapActions('namespaced/module', [
'myAction',
'myOtherAction'
])
}
}
命名空间可以由模块的文件名决定。例如,给定一个文件 - moduleA.js - getter、mutations、actions 将命名为 moduleA/someGetter、moduleA/someAction、moduleA/someMutation。
...mapActions('moduleA', [
'someAction',
'anotherAction'
])
当模块被注册时,它的所有getter、actions和mutations都会根据模块注册的路径自动命名空间
另一种方法是使用registerModule 方法,它允许动态运行时注册:
// register a module `myModule`
store.registerModule('myModule', {
// ...
})
// register a nested module `nested/myModule`
store.registerModule(['nested', 'myModule'], {
// ...
})
【讨论】: