问题描述
axios请求数据时,直接catch错误响应,不读axios.get().then()方法中的response,而是直接跳到catch中的err,并且打印出错误信息
问题出现的环境背景及自己尝试过哪些方法
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
axios.get('/api/ac/app.json').then(response => {
if(response && response.status === 200) {
console.log('******')
if(response.data.errcode === 0){
try{
this.result = response.data.data;
} catch (err) {
throw new Error('数据错误')
}
}
} else {
this.$alert('接口的数据没有正确响应','请求接口有误',{
confirmButtonText: '确定',
callback: action => {
this.$message({
type: 'info',
message: '检查代码'
});
}
})
}
}).catch(err => {
console.log(err)
});
你期待的结果是什么?实际看到的错误信息又是什么?
期待的是response响应返回的json数据
实际看到的是
Error: Request failed with status code 404
at createErrorResponse (utils.js?98cb:117)
at Object.settle (utils.js?98cb:97)
at handleRequest (handle_request.js?fff0:73)
at eval (index.js?3efb:18)
at new Promise (<anonymous>)
at MockAdapter.eval (index.js?3efb:17)
at dispatchRequest (dispatchRequest.js?5c70:52)
接口404了 首先确认你这接口是否存在