I have an Laravel / Vue.js website and i need to detect when we lost the connection to the server and display an warning on the front.
But i can't find a proper way to do that. I saw that i should use axios like that but i don't know where to put this in my vue...
axios.request(options).catch(function(error) {
if (!error.response) {
// Connect
}
else {
// Disconnect
}
Thanks for your help
I have an Laravel / Vue.js website and i need to detect when we lost the connection to the server and display an warning on the front.
But i can't find a proper way to do that. I saw that i should use axios like that but i don't know where to put this in my vue...
axios.request(options).catch(function(error) {
if (!error.response) {
// Connect
}
else {
// Disconnect
}
Thanks for your help
Share Improve this question edited Feb 24, 2019 at 6:18 Prashant Pimpale 10.7k10 gold badges50 silver badges87 bronze badges asked Dec 12, 2017 at 8:39 HeloHelo 711 silver badge9 bronze badges1 Answer
Reset to default 8There is a property in browsers known as onLine
which is a boolean that tells the connection status.
Here: navigator.onLine
returns a boolean according to the connection status.
UPD: Also there are some events like HTMLElement.ononline
and HTMLElement.onoffline.
See this SO answer here: detect change on navigator.online