admin管理员组文章数量:1316974
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
本文标签: javascriptVuejsDetect if disconnectedStack Overflow
版权声明:本文标题:javascript - Vue.js - Detect if disconnected - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742019613a2414422.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论