使用axios
请求接口:
this.$http.post('xxx/register', this.formItem).then(function (response) {
// debugger
console.log(response)
}.bind(this)).catch(function (response) {
debugger
console.log(response) // 这里的response就是: {username: ["A user with that username already exists."]}
})
请问这里怎么判断是否是200的成功状态值呢?或许你会说在catch中捕获的就是接口失败错误,那么我怎么才能获取到status_code?
因为错误的时候console.log(response)
就是
{username: ["A user with that username already exists."]}
这里面没有错误代码的。
HTTP请求的状态码,浏览器是有明确的打印的:
在axios返回数据拦截器里面:
你最后return的是res.data,还是res。如果是res.data,直接在这一步就拦下了,改成res就好