useThemeStyle.js 665 B

12345678910111213141516171819202122232425
  1. import { computed } from 'vue'
  2. import { useThemeStore } from '@/stores/theme'
  3. /**
  4. * Shared composable for theme switching.
  5. *
  6. * Returns themeClass ('theme-dark' | 'theme-light') for class-based theming.
  7. * This is more reliable than CSS custom property cascade in mini-programs.
  8. *
  9. * Usage:
  10. * <view class="page-xxx" :class="themeClass">
  11. * const { themeClass } = useTheme()
  12. */
  13. export function useTheme() {
  14. const themeStore = useThemeStore()
  15. const themeClass = computed(() =>
  16. themeStore.theme === 'light' ? 'theme-light' : 'theme-dark'
  17. )
  18. return { themeClass, themeStore }
  19. }
  20. // Alias for backward compat
  21. export const useThemeStyle = useTheme