Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

374
Views
Nuxt + Vuex + Composition API - Difference between using promise and await in actions

I am currently working on a project with Nuxt(2), Vuex and Composition-API. Trying to fetch some "question content" data from an API like this:

const questions = computed(() => store.state['questions'].questions)
const { fetch } = useFetch(async () => {
    await store.dispatch('questions/fetchQuestions')
})
fetch()

I tried two methods to get the data in Actions.
With await:

async getQuestionDetail({ commit }, slug) {
    const resp = await this.$axios.$get(`${'api/question/' + slug}`)
    commit('setDetail', resp.data)
}

With promise:

async getQuestionDetail({ commit }, slug) {
    this.$axios.$get(`${'api/question/' + slug}`).then((response) => {
        commit('setDetail', response.data)
    })
}

When i tried to get data with await and go to the page that makes the request it works with no errors.

But when i refresh the page, i got this error:

Error: [vuex] do not mutate vuex store state outside mutation handlers.

When i get the data with a promise page works without any problems.

I would like to know what is causing this error even when i don't bind any data. What is the difference in behavior in these two methods?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!