fix(styles): fix css var is inserted repeatedly

This commit is contained in:
燕博文 2024-04-07 17:34:33 +08:00
parent 0fbb00cee1
commit 769d84a7f4

View File

@ -1,6 +1,7 @@
import type { GlobalThemeOverrides } from 'naive-ui'; import type { GlobalThemeOverrides } from 'naive-ui';
import { getColorByColorPaletteNumber, getColorPalette } from '@sa/color-palette'; import { getColorByColorPaletteNumber, getColorPalette } from '@sa/color-palette';
import { addColorAlpha, getRgbOfColor } from '@sa/utils'; import { addColorAlpha, getRgbOfColor } from '@sa/utils';
import { useStyleTag } from '@vueuse/core';
import { overrideThemeSettings, themeSettings } from '@/theme/settings'; import { overrideThemeSettings, themeSettings } from '@/theme/settings';
import { themeVars } from '@/theme/vars'; import { themeVars } from '@/theme/vars';
import { localStg } from '@/utils/storage'; import { localStg } from '@/utils/storage';
@ -129,6 +130,7 @@ function getCssVarByTokens(tokens: App.Theme.BaseToken) {
return styleStr; return styleStr;
} }
const { css: themeVarCss } = useStyleTag('', { id: 'theme-var-css' });
/** /**
* Add theme vars to html * Add theme vars to html
* *
@ -150,11 +152,7 @@ export function addThemeVarsToHtml(tokens: App.Theme.BaseToken, darkTokens: App.
} }
`; `;
const style = document.createElement('style'); themeVarCss.value = css + darkCss;
style.textContent = css + darkCss;
document.head.appendChild(style);
} }
/** /**