File tree Expand file tree Collapse file tree 4 files changed +577
-131
lines changed Expand file tree Collapse file tree 4 files changed +577
-131
lines changed Original file line number Diff line number Diff line change 2
2
import type { ConfigProviderTheme } from ' vant'
3
3
import { appName } from ' ~/constants'
4
4
5
- const mode = ref <ConfigProviderTheme >(' light' )
6
-
7
5
useHead ({
8
6
title: appName ,
9
7
})
8
+
9
+ const color = useColorMode ()
10
+ const mode = computed (() => color .value as ConfigProviderTheme )
11
+
10
12
</script >
11
13
12
14
<template >
Original file line number Diff line number Diff line change 18
18
"vue-router" : " ^4.3.0"
19
19
},
20
20
"devDependencies" : {
21
- "@antfu/eslint-config" : " ^2.9.0 " ,
22
- "@unocss/eslint-plugin" : " ^0.58.6 " ,
23
- "@unocss/nuxt" : " ^0.58.6 " ,
24
- "@unocss/preset-rem-to-px" : " ^0.58.6 " ,
21
+ "@antfu/eslint-config" : " ^2.11.5 " ,
22
+ "@unocss/eslint-plugin" : " ^0.58.8 " ,
23
+ "@unocss/nuxt" : " ^0.58.8 " ,
24
+ "@unocss/preset-rem-to-px" : " ^0.58.8 " ,
25
25
"@vant/nuxt" : " ^1.0.4" ,
26
26
"eslint" : " npm:eslint-ts-patch@^8.57.0-0" ,
27
27
"eslint-plugin-format" : " ^0.1.0" ,
Original file line number Diff line number Diff line change @@ -17,40 +17,49 @@ useHead({
17
17
}],
18
18
})
19
19
20
- const checked = ref <boolean >(false )
20
+ const checked = computed ({
21
+ get : () => color .value === ' dark' ,
22
+ set : (val ) => {
23
+ return val
24
+ },
25
+ })
21
26
22
27
function toggleDark() {
23
- checked .value = color .value === ' dark'
24
28
color .preference = color .value === ' dark' ? ' light' : ' dark'
25
29
}
26
30
</script >
27
31
28
32
<template >
29
- <VanCellGroup inset >
30
- <VanCell
31
- center
32
- title =" 🌗 暗黑模式"
33
- >
34
- <template #right-icon >
35
- <VanSwitch
36
- v-model =" checked"
37
- size =" 20px"
38
- aria-label =" on/off Dark Mode"
39
- @click =" toggleDark"
33
+ <ColorScheme
34
+ placeholder =" 正在加载"
35
+ tag =" span"
36
+ >
37
+ <VanCellGroup inset >
38
+ <VanCell
39
+ center
40
+ title =" 🌗 暗黑模式"
41
+ >
42
+ <template #right-icon >
43
+ <VanSwitch
44
+ v-model =" checked"
45
+ size =" 20px"
46
+ aria-label =" on/off Dark Mode"
47
+ @click =" toggleDark"
48
+ />
49
+ </template >
50
+ </VanCell >
51
+
52
+ <template
53
+ v-for =" item in menuItems "
54
+ :key =" item .route "
55
+ >
56
+ <!-- item.route -->
57
+ <VanCell
58
+ :title =" item.title"
59
+ to =" /"
60
+ is-link
40
61
/>
41
62
</template >
42
- </VanCell >
43
-
44
- <template
45
- v-for =" item in menuItems "
46
- :key =" item .route "
47
- >
48
- <!-- item.route -->
49
- <VanCell
50
- :title =" item.title"
51
- to =" /"
52
- is-link
53
- />
54
- </template >
55
- </VanCellGroup >
63
+ </VanCellGroup >
64
+ </ColorScheme >
56
65
</template >
You can’t perform that action at this time.
0 commit comments