可以使用Promise的then方法在Axios.catch方法中定义两种异常状态。
例如:
axios.get('http://example.com/')
.then(response => {
// 处理成功响应
})
.catch(error => {
if (error.response.status === 400) {
// 处理400错误
} else if (error.response.status === 401) {
// 处理401错误
} else {
// 处理其他错误
}
});
在这个例子中,如果请求返回400或401状态码,就会分别在catch方法中的if语句中处理。如果返回其他状态码,就会在else语句中处理。