Can computed be used in combination with axios? How should I use it? the data obtained by my return axios is always undefined.

detail: {
    get() {
      let detail
      const gameId = this.id
      querySingleGameDetail(gameId).then(response => {
        detail= response.data.data.detail//
      })
      return detail
    }
}
Feb.28,2021

detail: {
    get() {
        let detail
        const gameId = this.id
        querySingleGameDetail(gameId).then(response => {
        detail= response.data.data.detail
        return detail
        })
    }
}

replied to you in the comments under another question.
normally, you can use async and await to convert asynchronous requests into Synchronize

// 
async get () {
    var result = await getDetails(this.param)
    return result
}

but it seems to be forbidden to use this thing in computed, so you can't get the correct value of return, so use watch instead.

< hr >

found some instructions in eslint-plugin-vue

Computed properties should be synchronous ( calculation property needs to be of Synchronize. Asynchronous actions inside them may not work as expected and can lead to an unexpected behaviour, that's why you should avoid them. If you need async computed properties you might want to consider using additional plugin vue-async-computed
Menu