feat(@vant/cli): mobile site support dark mode

This commit is contained in:
chenjiahan
2022-01-26 15:57:28 +08:00
parent 966af9dd68
commit df24a3b683
10 changed files with 80 additions and 26 deletions

View File

@@ -10,10 +10,31 @@
</template>
<script>
import { watch } from 'vue';
import DemoNav from './components/DemoNav.vue';
import { useCurrentTheme } from '../common/iframe-sync';
import { config } from 'site-mobile-shared';
export default {
components: { DemoNav },
setup() {
const theme = useCurrentTheme();
watch(
theme,
(newVal, oldVal) => {
document.body.classList.remove(`van-doc-theme-${oldVal}`);
document.body.classList.add(`van-doc-theme-${newVal}`);
const { darkModeClass } = config.site;
if (darkModeClass) {
document.body.classList.toggle(darkModeClass, newVal === 'dark');
}
},
{ immediate: true }
);
},
};
</script>
@@ -24,6 +45,10 @@ body {
min-width: 100vw;
}
.van-doc-theme-dark {
background-color: var(--van-doc-background);
}
::-webkit-scrollbar {
width: 0;
background: transparent;