Mohammad Salim Hosen
Mohammad Salim Hosen

Reputation: 303

How to write an async function in a vuex module

I am using Nuxt fetch() lifecycle hook to fetch data from Vuex. My Store structure looks like this

 store/
--| index.js
--| dialog.js
--| country/
------| actions.js    // I want to use async call in this file
------| getters.js
------| mutations.js
------| state.js 

In my component I am using fetch like this

async fetch({ store }){
   await store.dispatch("country/fetchCountries")
},

My country/actions.js file look like this

export const fetchCountries = ({commit, dispatch}, form) => {

    // let response = await this.$axios.get('/countries'); 

}

Now, I can not use async in front of the function. How can i use async in front of this function?

Upvotes: 0

Views: 306

Answers (1)

kissu
kissu

Reputation: 46604

This one is not working ?

export const fetchCountries = async ({commit, dispatch}, form) => {

Upvotes: 1

Related Questions