The vue axios get request was successful, but the returned data is in catch

simple api encapsulation

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

call data and return

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))
      })
    }

return the result

Error Info:{"message":"","code":0,"data":[{"channelType":"","sumRecordNum":"0"},{"channelType":"","sumRecordNum":"0"}]}

you can see that the data request was successful (code=0 indicates success), but did not return

in then
Mar.30,2021

the encapsulation of your api is wrong.
axios does return a promise, but you then directly in api. You don't need then here.
if you want to then in api, you need to wrap it in new Promise, and then resoleve () goes out


.

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

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

})
}

Menu