empty.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <Nuxt />
  3. </template>
  4. <script lang="ts">
  5. import {
  6. useContext,
  7. onBeforeMount,
  8. watch,
  9. defineComponent,
  10. } from "@nuxtjs/composition-api"
  11. import { setupLocalPersistence } from "~/newstore/localpersistence"
  12. import { useSetting } from "~/newstore/settings"
  13. function updateThemes() {
  14. const { $colorMode } = useContext() as any
  15. // Apply theme updates
  16. const themeColor = useSetting("THEME_COLOR")
  17. const bgColor = useSetting("BG_COLOR")
  18. const fontSize = useSetting("FONT_SIZE")
  19. // Initially apply
  20. onBeforeMount(() => {
  21. document.documentElement.setAttribute("data-accent", themeColor.value)
  22. $colorMode.preference = bgColor.value
  23. document.documentElement.setAttribute("data-font-size", fontSize.value)
  24. })
  25. // Listen for updates
  26. watch(themeColor, () =>
  27. document.documentElement.setAttribute("data-accent", themeColor.value)
  28. )
  29. watch(bgColor, () => ($colorMode.preference = bgColor.value))
  30. watch(fontSize, () =>
  31. document.documentElement.setAttribute("data-font-size", fontSize.value)
  32. )
  33. }
  34. export default defineComponent({
  35. setup() {
  36. updateThemes()
  37. },
  38. beforeMount() {
  39. setupLocalPersistence()
  40. },
  41. })
  42. </script>