Добавлены настройки темы по умолчанию
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { inject, ref, computed } from 'vue'
|
||||
import { resolveTheme } from '../config/applyTheme'
|
||||
|
||||
export function useTheme() {
|
||||
const theme = ref('dark')
|
||||
const config = inject('appConfig')
|
||||
const theme = ref(resolveTheme(config))
|
||||
|
||||
const isLightTheme = computed(() => theme.value === 'light')
|
||||
|
||||
@@ -15,16 +17,5 @@ export function useTheme() {
|
||||
applyTheme(theme.value === 'dark' ? 'light' : 'dark')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
const saved = localStorage.getItem('theme')
|
||||
if (saved === 'dark' || saved === 'light') {
|
||||
applyTheme(saved)
|
||||
return
|
||||
}
|
||||
|
||||
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
applyTheme(prefersDark ? 'dark' : 'light')
|
||||
})
|
||||
|
||||
return { theme, isLightTheme, toggleTheme }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user