下面是我的连接请求代码:
doLogin(this.login).then(response => {
var token = response.data.token;
localStorage.setItem('AUTH_TOKEN', JSON.stringify(token));
this.$router.push({name: 'Devices'});
});
}).catch(error => {
console.log(error.response.data.message);
});
catch()
部分适用于http错误(比如400
、404
、403
等等).但当我的服务器离线时,这个脚本只会抛出net::ERR_CONNECTION_REFUSED
.有没有办法处理此错误并让前端用户知道服务器当前处于脱机状态.?
这里是doLogin
()函数以防万一,
function doLogin(data) {
const url = 'http://localhost:3000/authenticate';
return axios.post(url,data);
}