-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.vue
38 lines (34 loc) · 956 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
36
37
38
<template>
<naive-config :theme-config="themeConfig">
<n-message-provider>
<n-el tag="div" style="background: var(--body-color); transition: .3s var(--cubic-bezier-ease-in-out);">
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
</n-el>
</n-message-provider>
</naive-config>
</template>
<script setup lang="ts">
import { useOsTheme } from 'naive-ui'
import { MOBILE_THEME } from './constants';
const { colorModePreference } = useNaiveColorMode();
const osThemeRef = useOsTheme()
const theme = computed<'dark' | 'light'>(() => (osThemeRef.value === 'dark' ? 'dark' : 'light'));
watch(
() => theme.value,
(val) => {
colorModePreference.set(val)
}
)
const themeConfig = {
mobile: MOBILE_THEME,
mobileOrTablet: MOBILE_THEME,
}
onMounted(() => {
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (prefersDark) {
colorModePreference.set('dark')
}
});
</script>