后台接口返回示例:
{
"errcode": 0,
"errmsg": "OK"
"res": {
"num": "100000000000000000"
}
}
前端使用 axios 发送请求:
axios.get(url.getData)
.then(res => {
res.data.res.num
})
.catch(err => console.log(err))
请问:
- 根据后台返回示例,要拿到 num,res.data.res.num 这样对吗?
- 返回示例里面的 errcode 与 res.status 应该不一样把?
- 请求成功之后走 .then( )里面,得到 res 之后是不是还需要根据 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 可以表示很多状态,现在0表示成功,以后可能还有1,2
所以最好判断下