fix: attach css variables to :root element (#11026)

This commit is contained in:
neverland
2022-09-11 09:11:53 +08:00
committed by GitHub
parent b6f2eb3e2a
commit 34360abd3b
79 changed files with 98 additions and 94 deletions
@@ -1,4 +1,4 @@
body {
:root {
// colors
--van-doc-black: #000;
--van-doc-white: #fff;
@@ -138,8 +138,8 @@ export default {
currentTheme: {
handler(newVal, oldVal) {
window.localStorage.setItem('vantTheme', newVal);
document.body.classList.remove(`van-doc-theme-${oldVal}`);
document.body.classList.add(`van-doc-theme-${newVal}`);
document.documentElement.classList.remove(`van-doc-theme-${oldVal}`);
document.documentElement.classList.add(`van-doc-theme-${newVal}`);
syncThemeToChild(newVal);
},
immediate: true,
+7 -3
View File
@@ -24,12 +24,15 @@ export default {
watch(
theme,
(newVal, oldVal) => {
document.body.classList.remove(`van-doc-theme-${oldVal}`);
document.body.classList.add(`van-doc-theme-${newVal}`);
document.documentElement.classList.remove(`van-doc-theme-${oldVal}`);
document.documentElement.classList.add(`van-doc-theme-${newVal}`);
const { darkModeClass } = config.site;
if (darkModeClass) {
document.body.classList.toggle(darkModeClass, newVal === 'dark');
document.documentElement.classList.toggle(
darkModeClass,
newVal === 'dark'
);
}
},
{ immediate: true }
@@ -43,6 +46,7 @@ export default {
body {
min-width: 100vw;
background-color: inherit;
}
.van-doc-theme-light {