使用 axios 请求接口
axios(option).then(res => {
console.log(res);
}).catch(err => {
console.log(err);
})
接口返回 422,在 catch 里打印出来的 err 是:Error: Request failed with status code 422
没有接口返回来的错误信息
那么如何拿到接口返回来的错误信息呢?
用 err.response 可以拿到,即:
axios(option).then(res => {
console.log(res);
}).catch(err => {
console.log(err.response);
})