This works just fine.
created() {
this['shared/getPosts']();
this['posts/getPosts']();
},
methods: {
...mapActions(['shared/getPosts', 'posts/getPosts']),
},
But, I was wondering, is there a way to make below code work as expected, please refer comment:
created() {
this.getPosts(); // triggers last method
},
methods: {
...mapActions('shared', ['getPosts']), // how to trigger this?
...mapActions('posts', ['getPosts']), // this gets triggered.
},
Just rename like so
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()`
}),
},
More info here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With