-
Notifications
You must be signed in to change notification settings - Fork 79
/
app.vue
35 lines (30 loc) · 865 Bytes
/
app.vue
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
<template>
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
</template>
<script>
import EventBus from '@/layouts/AppEventBus';
export default {
mounted() {
EventBus.on('dark-mode-toggle', this.darkModeToggleListener);
},
beforeUnmount() {
EventBus.off('dark-mode-toggle', this.darkModeToggleListener);
},
methods: {
darkModeToggleListener(event) {
if (!document.startViewTransition) {
this.toggleDarkMode(event);
return;
}
document.startViewTransition(() => this.toggleDarkMode(event));
},
toggleDarkMode() {
document.documentElement.classList.toggle('p-dark');
this.$appState.darkTheme = !this.$appState.darkTheme;
EventBus.emit('dark-mode-toggle-complete');
}
}
};
</script>