Skip to content

Commit d4ccd4c

Browse files
committed
修复夜间模式刷新问题
1 parent e24a3e1 commit d4ccd4c

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

front/src/components/NavHeader.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ import { useThemeStore } from '@/stores/themeStore'
101101
import { useMainStore } from '@/stores'
102102
103103
const themeStore = useThemeStore()
104+
themeStore.applyTheme()
105+
104106
const store = useMainStore()
105107
106108
const props = defineProps<{

front/src/stores/themeStore.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineStore } from 'pinia'
2-
import { ref } from 'vue'
2+
import { ref, onMounted } from 'vue'
33

44
export const useThemeStore = defineStore('theme', () => {
55
const isDarkTheme = ref(false)
@@ -9,9 +9,19 @@ export const useThemeStore = defineStore('theme', () => {
99
document.documentElement.classList.toggle('dark', isDarkTheme.value)
1010
}
1111

12+
const applyTheme = () => {
13+
document.documentElement.classList.toggle('dark', isDarkTheme.value)
14+
}
15+
16+
// Check the saved theme when the store is created
17+
onMounted(() => {
18+
applyTheme()
19+
})
20+
1221
return {
1322
isDarkTheme,
1423
toggleTheme,
24+
applyTheme
1525
}
1626
}, {
1727
persist: true

front/src/views/Login.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ import AppLayout from '@/components/AppLayout.vue'
4343
import { api } from '@/api'
4444
4545
const themeStore = useThemeStore()
46+
themeStore.applyTheme()
47+
4648
const router = useRouter()
4749
const store = useMainStore()
4850
const loading = ref(false)

0 commit comments

Comments
 (0)