mirror of
https://github.com/koel/koel
synced 2024-12-29 22:13:06 +00:00
21 lines
554 B
TypeScript
21 lines
554 B
TypeScript
import { computed, onUnmounted, ref } from 'vue'
|
|
|
|
export const useNetworkStatus = () => {
|
|
const online = ref(navigator.onLine)
|
|
const offline = computed(() => !online.value)
|
|
|
|
const updateOnlineStatus = () => (online.value = navigator.onLine)
|
|
|
|
window.addEventListener('online', updateOnlineStatus)
|
|
window.addEventListener('offline', updateOnlineStatus)
|
|
|
|
onUnmounted(() => {
|
|
window.removeEventListener('online', updateOnlineStatus)
|
|
window.removeEventListener('offline', updateOnlineStatus)
|
|
})
|
|
|
|
return {
|
|
online,
|
|
offline
|
|
}
|
|
}
|