在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ computed能和axios組合使用嗎?應該怎么用啊,我return axio

computed能和axios組合使用嗎?應該怎么用啊,我return axios獲取的數(shù)據(jù)老是undefined

detail: {
    get() {
      let detail
      const gameId = this.id
      querySingleGameDetail(gameId).then(response => {
        detail= response.data.data.detail//我們的結構就是這樣的
      })
      return detail
    }
}
回答
編輯回答
悶油瓶

在另一個問題下的評論里回復過你了。
正常來講可以使用async和await將異步請求轉化為同步的寫法

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

但是computed里好像禁止使用這個東西,拿不到正確的return的值,所以還是用watch吧。


在eslint-plugin-vue里找到了一些說明

Computed properties should be synchronous(計算屬性需要是同步的). 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
2018年9月10日 10:45
編輯回答
嫑吢丕
detail: {
    get() {
        let detail
        const gameId = this.id
        querySingleGameDetail(gameId).then(response => {
        detail= response.data.data.detail
        return detail
        })
    }
}
2018年2月27日 10:08