This repository was archived by the owner on Jan 3, 2026. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 11<script setup lang="ts">
22import { RouterView } from ' vue-router' ;
3+ import { darkTheme } from ' naive-ui' ;
4+ import { computed , onBeforeUnmount , onMounted , ref } from ' vue' ;
5+ import type { BuiltInGlobalTheme } from ' naive-ui/es/themes/interface' ;
6+
7+ const usingTheme = ref <BuiltInGlobalTheme | null >(null );
8+
9+ const isSystemDarkTheme = computed (
10+ () => !! window .matchMedia (' (prefers-color-scheme: dark)' )?.matches
11+ );
12+
13+ const updateTheme = () => {
14+ usingTheme .value = isSystemDarkTheme .value ? darkTheme : null ;
15+ };
16+
17+ onMounted (() => {
18+ updateTheme ();
19+ window .matchMedia (' (prefers-color-scheme: dark)' )
20+ .addEventListener (' change' , updateTheme );
21+ });
22+
23+ onBeforeUnmount (() => {
24+ window .matchMedia (' (prefers-color-scheme: dark)' )
25+ .removeEventListener (' change' , updateTheme );
26+ });
327 </script >
428
529<template >
6- <n-config-provider class =" size-full !bg-transparent" >
30+ <n-config-provider :theme = " usingTheme " class =" size-full !bg-transparent" >
731 <RouterView />
832 </n-config-provider >
933</template >
You can’t perform that action at this time.
0 commit comments