refactor: useTheme 中使用 initTheme 方法显式执行初始化 (#65)
This commit is contained in:
parent
6d0ef20b0b
commit
3b47cecfc9
@ -4,8 +4,10 @@ import { useTheme } from "@/hooks/useTheme"
|
|||||||
import { ElNotification } from "element-plus"
|
import { ElNotification } from "element-plus"
|
||||||
import zhCn from "element-plus/lib/locale/lang/zh-cn"
|
import zhCn from "element-plus/lib/locale/lang/zh-cn"
|
||||||
|
|
||||||
|
const { initTheme } = useTheme()
|
||||||
|
|
||||||
/** 初始化主题 */
|
/** 初始化主题 */
|
||||||
useTheme()
|
initTheme()
|
||||||
/** 将 Element Plus 的语言设置为中文 */
|
/** 将 Element Plus 的语言设置为中文 */
|
||||||
const locale = zhCn
|
const locale = zhCn
|
||||||
|
|
||||||
|
@ -40,13 +40,15 @@ const setHtmlClassName = (value: ThemeName) => {
|
|||||||
document.documentElement.className = value
|
document.documentElement.className = value
|
||||||
}
|
}
|
||||||
|
|
||||||
watchEffect(() => {
|
const initTheme = () => {
|
||||||
const value = activeThemeName.value
|
watchEffect(() => {
|
||||||
setHtmlClassName(value)
|
const value = activeThemeName.value
|
||||||
setActiveThemeName(value)
|
setHtmlClassName(value)
|
||||||
})
|
setActiveThemeName(value)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/** 主题 hook */
|
/** 主题 hook */
|
||||||
export function useTheme() {
|
export function useTheme() {
|
||||||
return { themeList, activeThemeName, setTheme }
|
return { themeList, activeThemeName, initTheme, setTheme }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user