App.vue 827 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <router-view />
  3. </template>
  4. <script setup>
  5. import { Cookies, useQuasar } from "quasar";
  6. import { watch } from "vue";
  7. import { useI18n } from "vue-i18n";
  8. defineOptions({
  9. name: "App",
  10. });
  11. const { locale } = useI18n();
  12. const $q = useQuasar();
  13. // const systemTheme = window.matchMedia("(prefers-color-scheme: dark)").matches
  14. // ? "dark"
  15. // : "light";
  16. const systemTheme = "light";
  17. const theme = Cookies.get("theme") || systemTheme;
  18. $q.dark.set(theme == "dark");
  19. watch(
  20. () => $q.dark.isActive,
  21. (value) => {
  22. Cookies.set("theme", value ? "dark" : "light", {
  23. expires: 365,
  24. sameSite: "Lax",
  25. path: "/",
  26. });
  27. },
  28. );
  29. watch(
  30. () => locale.value,
  31. (value) => {
  32. Cookies.set("locale", value, {
  33. expires: 365,
  34. sameSite: "Lax",
  35. path: "/",
  36. });
  37. },
  38. );
  39. </script>