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

鍍金池/ 問(wèn)答/HTML/ vue axios get請(qǐng)求成功,但返回的數(shù)據(jù)卻在 catch 里

vue axios get請(qǐng)求成功,但返回的數(shù)據(jù)卻在 catch 里

簡(jiǎn)單的 api 封裝

export const weChatAndSinaAcount = () => {
  return $http.get(API_HOST + '/channel/getChannelRecordNum').then(res => res.data)
}

調(diào)用數(shù)據(jù),并返回

getWeChatAndSinaAcount () {
      weChatAndSinaAcount().then(res => {
        console.log(res)
        if (res.code === 1) {
          let data = res.data
          console.log(data)
        }
      }).catch(err => {
        console.log('Error Info:' + JSON.stringify(err))
      })
    }

返回結(jié)果

Error Info:{"message":"獲取微信、微博收錄量","code":0,"data":[{"channelType":"微信","sumRecordNum":"0"},{"channelType":"微博","sumRecordNum":"0"}]}

可以看出數(shù)據(jù)請(qǐng)求成功了(code=0表示成功),但是沒(méi)有在 then 中返回

回答
編輯回答
巷尾

export function getSystemDB () {
return new Promise((resolve, reject) => {

axios.get(API_HOST + '/channel/getChannelRecordNum', '')
  .then(response => {
    resolve(response.data)
  })
  .catch((error) => {
    reject(error)
  })

})
}

2018年2月15日 11:58
編輯回答
陪我終

你api的封裝錯(cuò)誤了
axios返回的的確是一個(gè)promise,但是你直接在api里面then了,這里是不需要then的,
如果你想在api里面then的話(huà),那么需要用new Promise包裝一下,然后resoleve()出去

2017年11月11日 18:48