I'm trying to reuse a method in multiple vuejs component. I'm using mixin to do this but async method is not working
I have a async method in mixin that wait for an axios call GET-AllDrafts to finish and then run a mutation that updated the draft state value to the returned data from axios call.
async orgUpdateMixin() {
await this.$store.dispatch('GET_AllDrafts')
.then(data => {
this.$store.commit('draftUpdate', data); //mutation
})
}
I'm running this method in mounted() method of my component.
mounted(){
this.orgUpdateMixin();
console.log(this.data);
}
But for some reason this.data is returning [] empty array. Is there a way to wait for mixin to finish first before continuing.
await this.orgUpdateMixin();?