refactor: use Nuxt 4 directory structure

This commit is contained in:
AnotiaWang
2025-02-28 16:16:02 +08:00
parent 7a87ed5def
commit c45d75fad2
31 changed files with 33 additions and 28 deletions

View File

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