This commit is contained in:
AnotiaWang
2025-02-11 09:00:04 +08:00
commit 2cbd20a1da
29 changed files with 9894 additions and 0 deletions

View File

@ -0,0 +1,31 @@
<script setup lang="ts">
import { usePreferredColorScheme } from '@vueuse/core'
const colorMode = useColorMode()
const preferredColor = usePreferredColorScheme()
const preference = computed(() => {
// 默认为自动,会跟随用户的浏览器切换
if (colorMode.preference === 'system') {
return preferredColor.value
}
return colorMode.preference
})
const toggleColorMode = () => {
colorMode.preference = preference.value === 'light' ? 'dark' : 'light'
}
</script>
<template>
<div>
<UButton
:icon="
preference === 'dark'
? 'i-heroicons-sun-20-solid'
: 'i-heroicons-moon-20-solid'
"
color="primary"
@click="toggleColorMode"
/>
</div>
</template>