处理断网登出

1.请求发出后未返回数据

//响应拦截
Axios.interceptors.response.use(function (response) {
if (!response) {
MessageBox({
message: "网络不好",
confirmButtonText: "刷新",
}).then((action) => {
location.reload();
});
return Promise.reject('error')
}

return response;
}, function (error) {
MessageBox({
message: "网络不好",
confirmButtonText: "刷新",
}).then((action) => {
location.reload();
});
// 处理统一的验证失效错误.
return Promise.reject(error);
});
2.请求未发出(断网)

//请求拦截
Axios.interceptors.request.use((config) => {
if (!navigator.onLine) {
MessageBox({
message: "网络不好",
confirmButtonText: "刷新",
}).then((action) => {
location.reload();
});
}
return config
}, (error) => {
MessageBox({
message: "网络不好",
confirmButtonText: "刷新",
}).then((action) => {
location.reload();
});
console.log(error);
if (error && error.response) {
console.log(error.response);
}
return Promise.reject('error')
});

posted @ 2022-07-18 22:35  就想来看看  阅读(54)  评论(0编辑  收藏  举报