I've a different approach for dispatching an action. There's no click handler anywhere in the component but relies on event hub like below:
created() {
eventHub.$on('eventName', this.onCall)
},
methods: {
...mapActions([
'dispatcher'
]),
onCall() {
this.dispatcher({
dataA: this.dataA,
dataB: this.dataB,
dataC: this.dataC
})
}
}
So, you can see onCall
is called and inside that the dispatcher is called. I would like to know if there's any way use mapActions something like below:
created() {
eventHub.$on('eventName', this.dispatcher)
},
methods: {
...mapActions({
type: 'dispatcher',
payload: {
dataA: this.dataA,
dataB: this.dataB,
dataC: this.dataC
}
})
}
But looking at the api , I couldn't understand if I can use such like that.
I can only think of this as a better approach for this:
created() {
eventHub.$on('eventName', this.onCall)
},
methods: {
...mapActions([
// if there's any other
]),
onCall() {
this.$store.dispatch('dispatcher',{
dataA: this.dataA,
dataB: this.dataB,
dataC: this.dataC
})
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.