Skip to content

Commit ecdf6d6

Browse files
committed
feat: support dark mode
1 parent 7bf1ae1 commit ecdf6d6

File tree

4 files changed

+577
-131
lines changed

4 files changed

+577
-131
lines changed

app.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
import type { ConfigProviderTheme } from 'vant'
33
import { appName } from '~/constants'
44
5-
const mode = ref<ConfigProviderTheme>('light')
6-
75
useHead({
86
title: appName,
97
})
8+
9+
const color = useColorMode()
10+
const mode = computed(() => color.value as ConfigProviderTheme)
11+
1012
</script>
1113

1214
<template>

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
"vue-router": "^4.3.0"
1919
},
2020
"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",
2525
"@vant/nuxt": "^1.0.4",
2626
"eslint": "npm:eslint-ts-patch@^8.57.0-0",
2727
"eslint-plugin-format": "^0.1.0",

pages/index.vue

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,49 @@ useHead({
1717
}],
1818
})
1919
20-
const checked = ref<boolean>(false)
20+
const checked = computed({
21+
get: () => color.value === 'dark',
22+
set: (val) => {
23+
return val
24+
},
25+
})
2126
2227
function toggleDark() {
23-
checked.value = color.value === 'dark'
2428
color.preference = color.value === 'dark' ? 'light' : 'dark'
2529
}
2630
</script>
2731

2832
<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
4061
/>
4162
</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>
5665
</template>

0 commit comments

Comments
 (0)