Sye*_*yed 8 javascript vue.js vuex
这工作得很好。
created() {
this['shared/getPosts']();
this['posts/getPosts']();
},
methods: {
...mapActions(['shared/getPosts', 'posts/getPosts']),
},
Run Code Online (Sandbox Code Playgroud)
但是,我想知道,有没有办法让下面的代码按预期工作,请参考评论:
created() {
this.getPosts(); // triggers last method
},
methods: {
...mapActions('shared', ['getPosts']), // how to trigger this?
...mapActions('posts', ['getPosts']), // this gets triggered.
},
Run Code Online (Sandbox Code Playgroud)
Max*_*huk 14
像这样重命名
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()`
}),
},
Run Code Online (Sandbox Code Playgroud)
更多信息在这里
| 归档时间: |
|
| 查看次数: |
2785 次 |
| 最近记录: |