1
1
<script setup lang="ts">
2
2
import type { PickerColumn } from ' vant'
3
- import useAppStore from ' @/stores/modules/app'
4
3
import { languageColumns , locale } from ' @/utils/i18n'
5
4
6
- const appStore = useAppStore ()
7
- const checked = ref <boolean >(isDark .value )
8
-
9
- watch (
10
- () => isDark .value ,
11
- (newMode ) => {
12
- checked .value = newMode
13
- },
14
- { immediate: true },
15
- )
16
-
17
- function toggle() {
18
- toggleDark ()
19
- appStore .switchMode (isDark .value ? ' dark' : ' light' )
20
- }
21
-
22
5
const { t } = useI18n ()
23
6
7
+ const menuItems = computed (() => ([
8
+ { title: t (' menus.mockGuide' ), route: ' mock' },
9
+ { title: t (' menus.echartsDemo' ), route: ' charts' },
10
+ { title: t (' menus.unocssExample' ), route: ' unocss' },
11
+ { title: t (' menus.persistPiniaState' ), route: ' counter' },
12
+ { title: t (' menus.keepAlive' ), route: ' keepalive' },
13
+ { title: t (' menus.404Demo' ), route: ' unknown' },
14
+ ]))
15
+
24
16
const showLanguagePicker = ref (false )
25
17
const languageValues = ref <Array <string >>([locale .value ])
26
18
const language = computed (() => languageColumns .find (l => l .value === locale .value ).text )
@@ -30,37 +22,44 @@ function onLanguageConfirm(event: { selectedOptions: PickerColumn }) {
30
22
showLanguagePicker .value = false
31
23
}
32
24
33
- const menuItems = computed (() => ([
34
- { title: t (' menus.mockGuide' ), route: ' mock' },
35
- { title: t (' menus.echartsDemo' ), route: ' charts' },
36
- { title: t (' menus.unocssExample' ), route: ' unocss' },
37
- { title: t (' menus.persistPiniaState' ), route: ' counter' },
38
- { title: t (' menus.keepAlive' ), route: ' keepalive' },
39
- { title: t (' menus.404Demo' ), route: ' unknown' },
40
- ]))
25
+ const checked = ref <boolean >(isDark .value )
26
+
27
+ watchEffect (() => {
28
+ checked .value = isDark .value
29
+ })
30
+
31
+ function toggle(val : boolean ) {
32
+ checked .value = val
33
+ toggleDark ()
34
+ }
41
35
</script >
42
36
43
37
<template >
44
- <VanCellGroup :title =" t('menus.basicSettings')" :border =" false" :inset =" true" >
45
- <VanCell center :title =" t('menus.darkMode')" >
38
+ <van-cell-group :title =" t('menus.basicSettings')" :border =" false" :inset =" true" >
39
+ <van-cell center :title =" t('menus.darkMode')" >
46
40
<template #right-icon >
47
- <VanSwitch v-model =" checked" size =" 20px" aria-label =" on/off Dark Mode" @click =" toggle()" />
41
+ <van-switch
42
+ v-model =" checked"
43
+ size =" 20px"
44
+ aria-label =" on/off Dark Mode"
45
+ @change =" toggle"
46
+ />
48
47
</template >
49
- </VanCell >
48
+ </van-cell >
50
49
51
- <VanCell
50
+ <van-cell
52
51
is-link
53
52
:title =" t('menus.language')"
54
53
:value =" language"
55
54
@click =" showLanguagePicker = true"
56
55
/>
57
- </VanCellGroup >
56
+ </van-cell-group >
58
57
59
- <VanCellGroup :title =" t('menus.exampleComponents')" :border =" false" :inset =" true" >
58
+ <van-cell-group :title =" t('menus.exampleComponents')" :border =" false" :inset =" true" >
60
59
<template v-for =" item in menuItems " :key =" item .route " >
61
- <VanCell :title =" item.title" :to =" item.route" is-link />
60
+ <van-cell :title =" item.title" :to =" item.route" is-link />
62
61
</template >
63
- </VanCellGroup >
62
+ </van-cell-group >
64
63
65
64
<van-popup v-model:show =" showLanguagePicker" position =" bottom" >
66
65
<van-picker
0 commit comments