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

鍍金池/ 問答/HTML/ axios 相關(guān)

axios 相關(guān)

后臺接口返回示例:

{
   "errcode": 0,
   "errmsg": "OK"
   "res": {
     "num": "100000000000000000"
   }
}

前端使用 axios 發(fā)送請求:

axios.get(url.getData)
.then(res => {
    res.data.res.num
})
.catch(err => console.log(err))

請問:

  1. 根據(jù)后臺返回示例,要拿到 num,res.data.res.num 這樣對嗎?
  2. 返回示例里面的 errcode 與 res.status 應(yīng)該不一樣把?
  3. 請求成功之后走 .then( )里面,得到 res 之后是不是還需要根據(jù) errcode 判斷一下?

例如:

axios.get(url.getData)
.then(res => {
    if (res.data.errcode === 0) {
        console.log(res.data.res.num)
    } else {
        console.log(res.data.errmsg)
    }
})
.catch(err => console.log(err))


回答
編輯回答
莓森

打印下res看看是什么,然后看怎么取吧
errcode 可以表示很多狀態(tài),現(xiàn)在0表示成功,以后可能還有1,2
所以最好判斷下

2017年1月8日 16:30