0

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?

1 Answer 1

1

This one is not working ?

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your solution. It worked but another problem occured. this.$axios was not working. But I found out another solution. I wrapped all function inside export default{ async fetchCountries(){ } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.