-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.vue
39 lines (34 loc) · 1.05 KB
/
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
36
37
38
<template>
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
</template>
<script setup lang="ts">
const mq = window.matchMedia('(prefers-color-scheme: dark)')
const configStore = useConfigStore()
const theme = useTheme()
const themeSwitch = (e) => {
if (configStore.theme !== 'system') return
theme.global.name.value = theme.global.current.value.dark ? 'light' : 'dark'
}
onBeforeMount(() => {
if (configStore.theme === 'dark') {
theme.global.name.value = 'dark'
} else if (configStore.theme === 'light') {
theme.global.name.value = 'light'
} else if (configStore.theme === 'system') {
theme.global.name.value = mq.matches ? 'dark' : 'light'
mq.addEventListener('change', themeSwitch)
}
})
watch(() => configStore.theme, (newValue) => {
if (newValue === 'dark') {
theme.global.name.value = 'dark'
} else if (newValue === 'light') {
theme.global.name.value = 'light'
} else if (newValue === 'system') {
theme.global.name.value = mq.matches ? 'dark' : 'light'
mq.addEventListener('change', themeSwitch)
}
})
</script>