refactor: useTheme 中使用 initTheme 方法显式执行初始化 (#65)

This commit is contained in:
betterwusy 2023-03-28 17:48:39 +08:00 committed by GitHub
parent 6d0ef20b0b
commit 3b47cecfc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -4,8 +4,10 @@ import { useTheme } from "@/hooks/useTheme"
import { ElNotification } from "element-plus"
import zhCn from "element-plus/lib/locale/lang/zh-cn"
const { initTheme } = useTheme()
/** 初始化主题 */
useTheme()
initTheme()
/** 将 Element Plus 的语言设置为中文 */
const locale = zhCn

View File

@ -40,13 +40,15 @@ const setHtmlClassName = (value: ThemeName) => {
document.documentElement.className = value
}
watchEffect(() => {
const initTheme = () => {
watchEffect(() => {
const value = activeThemeName.value
setHtmlClassName(value)
setActiveThemeName(value)
})
})
}
/** 主题 hook */
export function useTheme() {
return { themeList, activeThemeName, setTheme }
return { themeList, activeThemeName, initTheme, setTheme }
}