App.vue 892 Bytes
Newer Older
abergavenny's avatar
abergavenny committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<script setup>
import { onMounted, onUnmounted } from 'vue'
import { RouterView } from 'vue-router'

import { useSessionStore } from '@/stores/session'

const session = useSessionStore()

function onConnectionChange(event) {
  if (event.type === 'online') {
    session.setConnectionState(true)
  } else {
    session.setConnectionState(false)
  }
}

onMounted(() => {
  if ('onLine' in navigator) {
    session.setConnectionState(navigator.onLine)
    
    window.addEventListener('online', onConnectionChange)
    window.addEventListener('offline', onConnectionChange)
  }
})

onUnmounted(() => {
  window.removeEventListener('online', onConnectionChange)
  window.removeEventListener('offline', onConnectionChange)
})
</script>

<template>
  <RouterView />
</template>

<style>
#app {
  overflow: hidden;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}
</style>