ThemeToggle.vue 995 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <view class="theme-switcher">
  3. <text
  4. class="theme-btn"
  5. :class="{ active: isDark }"
  6. @click="setDark"
  7. >深色</text>
  8. <text
  9. class="theme-btn"
  10. :class="{ active: !isDark }"
  11. @click="setLight"
  12. >浅色</text>
  13. </view>
  14. </template>
  15. <script setup>
  16. import { computed } from 'vue'
  17. import { useThemeStore } from '@/stores/theme'
  18. const themeStore = useThemeStore()
  19. const isDark = computed(() => themeStore.theme === 'dark')
  20. function setDark() {
  21. themeStore.setTheme('dark')
  22. }
  23. function setLight() {
  24. themeStore.setTheme('light')
  25. }
  26. </script>
  27. <style>
  28. .theme-switcher {
  29. display: inline-flex;
  30. align-items: center;
  31. background: rgba(255, 255, 255, 0.12);
  32. border-radius: 8px;
  33. padding: 2px;
  34. gap: 2px;
  35. }
  36. .theme-btn {
  37. font-size: 12px;
  38. padding: 4px 12px;
  39. border-radius: 6px;
  40. color: rgba(255, 255, 255, 0.7);
  41. transition: all 0.2s ease;
  42. line-height: 1.4;
  43. }
  44. .theme-btn.active {
  45. background: rgba(255, 255, 255, 0.95);
  46. color: #1A1A2E;
  47. font-weight: 600;
  48. }
  49. </style>