Created
November 3, 2019 05:44
-
-
Save BlackMix/cd6a540250dc3e277ae739a46939bcbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
data: () => ({ | |
online: true | |
}), | |
mounted () { | |
if (!window.navigator) { | |
this.online = false | |
return | |
} | |
this.online = Boolean(window.navigator.onLine) | |
window.addEventListener('offline', this._NetworkStatus) | |
window.addEventListener('online', this._NetworkStatus) | |
}, | |
methods: { | |
_NetworkStatus ({ type }) { | |
this.online = type === 'online' | |
} | |
}, | |
beforeDestroy () { | |
window.removeEventListener('offline', this._NetworkStatus) | |
window.removeEventListener('online', this._NetworkStatus) | |
} | |
} |
Author
BlackMix
commented
Nov 3, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment