Search code examples
javascriptvue.jsnuxt.jsvuex

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?


Solution

  • This one is not working ?

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