mirror of
https://github.com/un-pany/v3-admin-vite.git
synced 2025-04-21 03:19:19 +08:00
perf: 代码优化 hooks/useTheme
This commit is contained in:
parent
ee2ee7e1da
commit
63844a8f2e
@ -31,19 +31,22 @@ const themeList: IThemeList[] = [
|
||||
/** 正在应用的主题名称 */
|
||||
const activeThemeName = ref<ThemeName>(getActiveThemeName() || DEFAULT_THEME_NAME)
|
||||
|
||||
/** 设置主题 */
|
||||
const setTheme = (value: ThemeName) => {
|
||||
activeThemeName.value = value
|
||||
}
|
||||
|
||||
/** 在 html 根元素上挂载 class */
|
||||
const setHtmlClassName = (value: ThemeName) => {
|
||||
const setHtmlRootClassName = (value: ThemeName) => {
|
||||
document.documentElement.className = value
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
const initTheme = () => {
|
||||
// watchEffect 来收集副作用
|
||||
watchEffect(() => {
|
||||
const value = activeThemeName.value
|
||||
setHtmlClassName(value)
|
||||
setHtmlRootClassName(value)
|
||||
setActiveThemeName(value)
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user