1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| import { ref, onBeforeUnmount } from 'vue'
|
| const useNetwork = () => {
| const online = ref(true)
|
| const updateNetwork = () => {
| online.value = navigator.onLine
| }
|
| window.addEventListener('online', updateNetwork)
| window.addEventListener('offline', updateNetwork)
|
| onBeforeUnmount(() => {
| window.removeEventListener('online', updateNetwork)
| window.removeEventListener('offline', updateNetwork)
| })
|
| return { online }
| }
|
| export { useNetwork }
|
|