Skip to content

Instantly share code, notes, and snippets.

@BlackMix
Created November 3, 2019 05:44
Show Gist options
  • Save BlackMix/cd6a540250dc3e277ae739a46939bcbd to your computer and use it in GitHub Desktop.
Save BlackMix/cd6a540250dc3e277ae739a46939bcbd to your computer and use it in GitHub Desktop.
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)
}
}
@BlackMix
Copy link
Author

BlackMix commented Nov 3, 2019

mixins: [offline],
watch: {
  online () {
      return !this.online ? 'OFFLINE' : "ONLINE"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment