我正在制作一个脚本来从我的 api 中获取一些数据:
const success = (response) => {
console.log(response);
};
const failed = (error) => {
console.log(error);
};
axios.$http.get('/somedata')
.then((response) => {
success(response.data);
})
.catch((error) => {
failed(error);
});
/somepage
是一个不存在的页面,所以它返回一个 404。但问题没有处理这个问题。为什么不?在我的控制台中,我有错误TypeError: Cannot read property 'data' of undefined
。为什么它不运行该failed()
功能?我不明白。