App.vue 788 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 theme = Cookies.get("theme") || systemTheme;
  17. $q.dark.set(theme == "dark");
  18. watch(
  19. () => $q.dark.isActive,
  20. (value) => {
  21. Cookies.set("theme", value ? "dark" : "light", {
  22. expires: 365,
  23. sameSite: "Lax",
  24. path: "/",
  25. });
  26. },
  27. );
  28. watch(
  29. () => locale.value,
  30. (value) => {
  31. Cookies.set("locale", value, {
  32. expires: 365,
  33. sameSite: "Lax",
  34. path: "/",
  35. });
  36. },
  37. );
  38. </script>