Skip to content

Alert 警告提示 ​

显示一条引起用户注意的提示。

基础用法 ​

网页近似预览,真机效果以 HarmonyOS 渲染为准。

状态变体 ​

success | warning | info(以及 destructive),普通或柔和样式。

网页近似预览,真机效果以 HarmonyOS 渲染为准。

操作、可关闭、紧凑 ​

被关闭的提示会以 alert 动效自行隐藏,并触发 onDismiss。

网页近似预览,真机效果以 HarmonyOS 渲染为准。

API ​

从组件库源码中的 @Param / @Event / @BuilderParam 声明自动提取。

SAlert ​

shadcn-vue 的 Alert:relative w-full rounded-lg border px-4 py-3 text-sm grid grid-cols-[16px_1fr] gap-x-3 gap-y-0.5 items-start,背景为 bg-card。destructive 变体会将标题 / 图标着色为 text-destructive,描述着色为 text-destructive/90。

heading / description 是无需插槽时标题 / 描述的快捷写法。

变体:default | destructive | success | warning | info(标题与图标采用对应的色调)。其他选项:soft(带色调的背景和边框)、compact(更紧凑的内边距,居中排列)、actionLabel + onAction(尾部的 outline 按钮)、dismissible(尾部的 ×;警告会自行隐藏并触发 onDismiss)。

属性类型默认值说明
variantAlertVariant
AlertVariant = 'default' | 'destructive' | 'success' | 'warning' | 'info'
'default'
iconstring | undefinedundefined显示在前导列中的 lucide 图标名称。
headingResourceStr | undefinedundefined
descriptionResourceStr | undefinedundefined
softbooleanfalse带变体颜色的浅色背景与边框。
compactbooleanfalse更紧凑的内边距(px-3 py-2),内容居中。
actionLabelResourceStr | undefinedundefined尾部操作按钮的文字。
dismissiblebooleanfalse尾部的 × 按钮;警告会自行隐藏(动效 key 为 'alert')并触发 onDismiss。
modifierAttributeModifier<RowAttribute>new SparkNoopModifier<RowAttribute>()
tokensAlertTokens{}实例级令牌覆盖(实例 → 主题 --alert-* → 配方),参见 {@link AlertTokens}。
事件类型默认值说明
onAction() => void() => { }
onDismiss() => void() => { }

插槽: 子组件(尾随闭包)

SAlertTitle ​

col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight。

属性类型默认值说明
textResourceStr''

SAlertDescription ​

text-muted-foreground col-start-2 text-sm [&_p]:leading-relaxed(destructive:text-destructive/90)。

属性类型默认值说明
textResourceStr | undefinedundefined

插槽: 子组件(尾随闭包)

MIT Licensed