2021-04-04 21:49:41 +08:00
|
|
|
<template>
|
2021-04-06 23:47:32 +08:00
|
|
|
<ParentLayout>
|
|
|
|
<template v-slot:navbar-after>
|
|
|
|
<ThemeToggle />
|
|
|
|
</template>
|
|
|
|
</ParentLayout>
|
2021-04-04 21:49:41 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-04-06 23:47:32 +08:00
|
|
|
import ParentLayout from "@vuepress/theme-default/lib/layouts/Layout.vue";
|
|
|
|
import ThemeToggle from "../components/ThemeToggle.vue";
|
|
|
|
import { defineComponent } from "vue";
|
|
|
|
|
|
|
|
export default defineComponent({
|
2021-04-04 21:49:41 +08:00
|
|
|
components: {
|
2021-04-06 19:05:35 +08:00
|
|
|
ParentLayout,
|
2021-04-06 23:47:32 +08:00
|
|
|
ThemeToggle,
|
|
|
|
},
|
|
|
|
beforeMount() {
|
|
|
|
function setTheme(newTheme) {
|
|
|
|
const html = document.getElementsByTagName("html")[0];
|
|
|
|
html.setAttribute("theme", newTheme);
|
|
|
|
}
|
|
|
|
var dark = window.matchMedia("(prefers-color-scheme: dark)");
|
|
|
|
dark.addEventListener("change", (e) => {
|
|
|
|
setTheme(e.matches ? "dark" : "light");
|
|
|
|
});
|
|
|
|
setTheme(dark.matches ? "dark" : "light");
|
2021-04-06 19:05:35 +08:00
|
|
|
},
|
2021-04-04 21:49:41 +08:00
|
|
|
});
|
|
|
|
</script>
|