使用 title 属性设置警告的标题。
<template>
<UAlert title="Heads up!" />
</template>
使用 description 属性设置警告的描述。
<template>
<UAlert title="Heads up!" description="You can change the primary color in your app config." />
</template>
使用 icon 属性显示一个 图标。
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
icon="i-lucide-terminal"
/>
</template>
使用 avatar 属性显示一个 头像。
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
:avatar="{
src: 'https://github.com/nuxt.png'
}"
/>
</template>
使用 color 属性更改警告的颜色。
<template>
<UAlert
color="neutral"
title="Heads up!"
description="You can change the primary color in your app config."
icon="i-lucide-terminal"
/>
</template>
使用 variant 属性更改警告的变体。
<template>
<UAlert
color="neutral"
variant="subtle"
title="Heads up!"
description="You can change the primary color in your app config."
icon="i-lucide-terminal"
/>
</template>
使用 close 属性显示一个 按钮 来关闭警告。
update:open 事件。<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
color="neutral"
variant="outline"
close
/>
</template>
您可以传递 Button 组件的任何属性来自定义它。
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
color="neutral"
variant="outline"
:close="{
color: 'primary',
variant: 'outline',
class: 'rounded-full'
}"
/>
</template>
使用 close-icon 属性自定义关闭按钮的 图标。默认为 i-lucide-x。
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
color="neutral"
variant="outline"
close
close-icon="i-lucide-arrow-right"
/>
</template>
使用 actions 属性为警告添加一些 按钮 操作。
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
color="neutral"
variant="outline"
:actions="[
{
label: 'Action 1'
},
{
label: 'Action 2',
color: 'neutral',
variant: 'subtle'
}
]"
/>
</template>
使用 orientation 属性更改警告的方向。
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
color="neutral"
variant="outline"
orientation="horizontal"
:actions="[
{
label: 'Action 1'
},
{
label: 'Action 2',
color: 'neutral',
variant: 'subtle'
}
]"
/>
</template>
class 属性使用 class 属性覆盖警告的基本样式。
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
class="rounded-none"
/>
</template>
ui 属性使用 ui 属性覆盖警告的插槽样式。
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
icon="i-lucide-rocket"
:ui="{
icon: 'size-11'
}"
/>
</template>
| 属性 | 默认值 | 类型 |
|---|---|---|
as | 'div' | any此组件应渲染为的元素或组件。 |
title | string | |
description | string | |
图标 | any | |
avatar | AvatarProps
| |
color | 'primary' | "error" | "primary" | "secondary" | "success" | "info" | "warning" | "neutral" |
variant | 'solid' | "solid" | "outline" | "soft" | "subtle" |
orientation | 'vertical' | "vertical" | "horizontal"内容和操作之间的方向。 |
actions | ButtonProps[]显示操作列表
| |
close | false | boolean | Omit<ButtonProps, LinkPropsKeys>显示一个关闭按钮来关闭警告。 |
closeIcon | appConfig.ui.icons.close | any关闭按钮中显示的图标。 |
ui | { root?: ClassNameValue; wrapper?: ClassNameValue; title?: ClassNameValue; description?: ClassNameValue; icon?: ClassNameValue; avatar?: ClassNameValue; avatarSize?: ClassNameValue; actions?: ClassNameValue; close?: ClassNameValue; } |
| 插槽 | 类型 |
|---|---|
前置 | { ui: object; } |
title | {} |
description | {} |
actions | {} |
close | { ui: object; } |
| 事件 | 类型 |
|---|---|
update:open | [value: boolean] |
export default defineAppConfig({
ui: {
alert: {
slots: {
root: 'relative overflow-hidden w-full rounded-lg p-4 flex gap-2.5',
wrapper: 'min-w-0 flex-1 flex flex-col',
title: 'text-sm font-medium',
description: 'text-sm opacity-90',
icon: 'shrink-0 size-5',
avatar: 'shrink-0',
avatarSize: '2xl',
actions: 'flex flex-wrap gap-1.5 shrink-0',
close: 'p-0'
},
variants: {
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
variant: {
solid: '',
outline: '',
soft: '',
subtle: ''
},
orientation: {
horizontal: {
root: 'items-center',
actions: 'items-center'
},
vertical: {
root: 'items-start',
actions: 'items-start mt-2.5'
}
},
title: {
true: {
description: 'mt-1'
}
}
},
compoundVariants: [
{
color: 'primary',
variant: 'solid',
class: {
root: 'bg-primary text-inverted'
}
},
{
color: 'primary',
variant: 'outline',
class: {
root: 'text-primary ring ring-inset ring-primary/25'
}
},
{
color: 'primary',
variant: 'soft',
class: {
root: 'bg-primary/10 text-primary'
}
},
{
color: 'primary',
variant: 'subtle',
class: {
root: 'bg-primary/10 text-primary ring ring-inset ring-primary/25'
}
},
{
color: 'neutral',
variant: 'solid',
class: {
root: 'text-inverted bg-inverted'
}
},
{
color: 'neutral',
variant: 'outline',
class: {
root: 'text-highlighted bg-default ring ring-inset ring-default'
}
},
{
color: 'neutral',
variant: 'soft',
class: {
root: 'text-highlighted bg-elevated/50'
}
},
{
color: 'neutral',
variant: 'subtle',
class: {
root: 'text-highlighted bg-elevated/50 ring ring-inset ring-accented'
}
}
],
defaultVariants: {
color: 'primary',
variant: 'solid'
}
}
}
})
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
alert: {
slots: {
root: 'relative overflow-hidden w-full rounded-lg p-4 flex gap-2.5',
wrapper: 'min-w-0 flex-1 flex flex-col',
title: 'text-sm font-medium',
description: 'text-sm opacity-90',
icon: 'shrink-0 size-5',
avatar: 'shrink-0',
avatarSize: '2xl',
actions: 'flex flex-wrap gap-1.5 shrink-0',
close: 'p-0'
},
variants: {
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
variant: {
solid: '',
outline: '',
soft: '',
subtle: ''
},
orientation: {
horizontal: {
root: 'items-center',
actions: 'items-center'
},
vertical: {
root: 'items-start',
actions: 'items-start mt-2.5'
}
},
title: {
true: {
description: 'mt-1'
}
}
},
compoundVariants: [
{
color: 'primary',
variant: 'solid',
class: {
root: 'bg-primary text-inverted'
}
},
{
color: 'primary',
variant: 'outline',
class: {
root: 'text-primary ring ring-inset ring-primary/25'
}
},
{
color: 'primary',
variant: 'soft',
class: {
root: 'bg-primary/10 text-primary'
}
},
{
color: 'primary',
variant: 'subtle',
class: {
root: 'bg-primary/10 text-primary ring ring-inset ring-primary/25'
}
},
{
color: 'neutral',
variant: 'solid',
class: {
root: 'text-inverted bg-inverted'
}
},
{
color: 'neutral',
variant: 'outline',
class: {
root: 'text-highlighted bg-default ring ring-inset ring-default'
}
},
{
color: 'neutral',
variant: 'soft',
class: {
root: 'text-highlighted bg-elevated/50'
}
},
{
color: 'neutral',
variant: 'subtle',
class: {
root: 'text-highlighted bg-elevated/50 ring ring-inset ring-accented'
}
}
],
defaultVariants: {
color: 'primary',
variant: 'solid'
}
}
}
})
]
})