ColorModeButton 组件扩展了 Button 组件,因此您可以传递任何属性,例如 color、variant、size 等。
<template>
<UColorModeButton />
</template>
color="neutral" 和 variant="ghost"。使用 app.config.ts 通过 ui.icons 属性来自定义图标。
export default defineAppConfig({
ui: {
icons: {
light: 'i-ph-sun',
dark: 'i-ph-moon'
}
}
})
使用 vite.config.ts 通过 ui.icons 属性来自定义图标。
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
icons: {
light: 'i-ph-sun',
dark: 'i-ph-moon'
}
}
})
]
})
由于按钮被包装在ClientOnly组件中,您可以传递一个 fallback 插槽来在组件加载时显示一个占位符。
<template>
<UColorModeButton>
<template #fallback>
<UButton loading variant="ghost" color="neutral" />
</template>
</UColorModeButton>
</template>
| 属性 | 默认值 | 类型 |
|---|---|---|
as | 'button' | any此组件在不是链接时应呈现的元素或组件。 |
color | 'neutral' | "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" |
variant | 'ghost' | "link" | "ghost" | "solid" | "outline" | "soft" | "subtle" |
trailingIcon | any在右侧显示图标。 | |
name | string | |
尾部 | boolean当为 | |
loading | boolean当为 | |
图标 | any根据 | |
尺寸 | 'md' | "md" | "xs" | "sm" | "lg" | "xl" |
avatar | AvatarProps在左侧显示头像。
| |
autofocus | false | true | "true" | "false" | |
disabled | boolean | |
type | 'button' | "reset" | "submit" | "button"当不是链接时,按钮的类型。 |
label | string | |
activeColor | "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" | |
activeVariant | "link" | "ghost" | "solid" | "outline" | "soft" | "subtle" | |
正方形 | boolean以四边等距内边距渲染按钮。 | |
block | boolean渲染全宽按钮。 | |
loadingAuto | boolean根据 | |
前置 | boolean当为 | |
leadingIcon | any在左侧显示图标。 | |
loadingIcon | appConfig.ui.icons.loading | any当 |
ui | { base?: ClassNameValue; label?: ClassNameValue; leadingIcon?: ClassNameValue; leadingAvatar?: ClassNameValue; leadingAvatarSize?: ClassNameValue; trailingIcon?: ClassNameValue; } |
| 插槽 | 类型 |
|---|