App.vue 1001 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <router-view />
  3. </template>
  4. <script setup>
  5. import { useQuasar } from "quasar";
  6. import { StatusBar, Style } from "@capacitor/status-bar";
  7. import { Capacitor } from "@capacitor/core";
  8. import { watch, onBeforeMount } from "vue";
  9. import { useI18n } from "vue-i18n";
  10. import { Preferences } from "@capacitor/preferences";
  11. defineOptions({
  12. name: "App",
  13. });
  14. const { locale } = useI18n();
  15. const $q = useQuasar();
  16. const updateStatusBar = async () => {
  17. if (!Capacitor.isNativePlatform()) {
  18. return;
  19. }
  20. await StatusBar.show();
  21. await StatusBar.setStyle({
  22. style: Style.Light,
  23. });
  24. };
  25. watch(
  26. () => locale.value,
  27. async (value) => {
  28. await Preferences.set({
  29. key: "locale",
  30. value,
  31. });
  32. },
  33. );
  34. onBeforeMount(async () => {
  35. $q.dark.set(false);
  36. await updateStatusBar();
  37. const { value: localePref } = await Preferences.get({
  38. key: "locale",
  39. });
  40. const userLocale = localePref || window.navigator.language;
  41. console.log(userLocale);
  42. });
  43. </script>