mapActions
用于组件的methods
属性。
// my-component.vue
import { mapActions } from 'vuex'
export default {
...
methods: {
...mapActions('namespaced/module', [
'myAction',
'myOtherAction'
])
}
}
命名空间可以由模块的文件名确定。例如,给定一个文件- moduleA.js
-干将,突变,行动将被作为命名空间moduleA/someGetter
,moduleA/someAction
,moduleA/someMutation
。
...mapActions('moduleA', [
'someAction',
'anotherAction'
])
注册模块后,将根据模块在其上注册的路径自动为其所有的获取,操作和变异命名空间。
另一种方法是使用registerModule
方法,该方法允许动态运行时注册:
// register a module `myModule`
store.registerModule('myModule', {
// ...
})
// register a nested module `nested/myModule`
store.registerModule(['nested', 'myModule'], {
// ...
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句