我有问题与nuxt覆盖axios响应。首先,我在空nodejs项目中尝试axios来检查资源是否可用。
axios
.head(
'https://needtocheckthislink'
)
.then(function(response) {
// here code 200
console.log(response.status);
})
.catch(function(error) {
// Some errors 403 / 404
console.log(error.response.status);
});
它工作正常,但在nuxt我无法从我的请求得到response.data。 Nuxt提供错误代码,但我无法解释。
// for 403
Error: "Network Error"
NuxtJS 2
createError
handleError
// for 404
Error: "Request failed with status code 404"
NuxtJS 3
createError
settle
handleLoad
我如何正确处理此请求?
因为我不确定这个解决方案是否在客户端:Axios我使用了基本的http头请求。
let client = new XMLHttpRequest();
client.open("GET", "http://testUrl", true);
client.send();
client.onreadystatechange = function() {
if(this.readyState == this.HEADERS_RECEIVED) {
if(client.status === 200){
console.log("res 200");
}
else if(client.status === 404){
console.log("err 404");
}
else if(client.status === 0){
console.log("forbiden")
}
client.abort();
}
}