ThemeSwitcher.vue 844 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <template>
  2. <v-switch
  3. v-model="themeValue"
  4. density="compact"
  5. inline
  6. false-value="light"
  7. false-icon="fas fa-sun"
  8. true-value="dark"
  9. true-icon="fas fa-moon"
  10. aria-label="Switch between light and dark theme"
  11. />
  12. </template>
  13. <script setup lang="ts">
  14. import {useTheme} from "vuetify";
  15. const theme = useTheme()
  16. const themeValue = ref(theme.global.name.value);
  17. onMounted(() => {
  18. watch(themeValue, (newVal) => {
  19. theme.global.name.value = newVal;
  20. localStorage.setItem('theme', newVal);
  21. });
  22. if (localStorage.getItem('theme')) {
  23. themeValue.value = localStorage.getItem('theme');
  24. theme.global.name.value = themeValue.value;
  25. }
  26. })
  27. </script>
  28. <style scoped lang="scss">
  29. .v-switch {
  30. min-width: 60px;
  31. max-width: 60px;
  32. min-height: 40px;
  33. max-height: 40px;
  34. }
  35. </style>