这很好用。
created() {
this['shared/getPosts']();
this['posts/getPosts']();
},
methods: {
...mapActions(['shared/getPosts', 'posts/getPosts']),
},
但是,我想知道,是否有一种方法可以使下面的代码按预期工作,请参阅注释:
created() {
this.getPosts(); // triggers last method
},
methods: {
...mapActions('shared', ['getPosts']), // how to trigger this?
...mapActions('posts', ['getPosts']), // this gets triggered.
},
答案 0 :(得分:3)
只是这样重命名
created() {
// call the first method
this.getSharedPosts();
// or second
this.getPosts();
},
methods: {
...mapActions('shared', {
getSharedPosts: 'getPosts', // <-- call it as `this.getSharedPosts()` in component
}),
...mapActions('posts', {
getPosts: 'getPosts', // <-- call it as `this.getPosts()`
}),
},
更多信息here