Skip to content

Alert 提示

Alert 用于在页面中展示重要的提示信息。VISTA B 直接使用 Element Plus 的 el-alert,它不属于浮层元素,不会自动消失,适合固定显示的状态提醒、规则说明和风险提示。

基础用法

Alert 提供 5 种类型,通过 type 设置,默认值为 info

vue
<el-alert title="Primary alert" type="primary" />
<el-alert title="Success alert" type="success" />
<el-alert title="Info alert" type="info" />
<el-alert title="Warning alert" type="warning" />
<el-alert title="Error alert" type="error" />

主题

通过 effect 设置主题,支持 lightdark,默认值为 light

vue
<el-alert title="Primary alert" type="primary" effect="dark" />
<el-alert title="Success alert" type="success" effect="dark" />
<el-alert title="Info alert" type="info" effect="dark" />
<el-alert title="Warning alert" type="warning" effect="dark" />
<el-alert title="Error alert" type="error" effect="dark" />

自定义关闭按钮

通过 closable 控制是否可关闭,通过 close-text 替换右侧关闭图标。关闭时会触发 close 事件。

等待关闭操作
vue
<script setup>
const hello = () => {
  console.log('Alert closed')
}
</script>

<template>
  <el-alert title="Unclosable alert" type="success" :closable="false" />
  <el-alert title="Customized close text" type="info" close-text="Gotcha" />
  <el-alert title="Alert with callback" type="warning" @close="hello" />
</template>

使用图标

设置 show-icon 后,会显示和类型匹配的图标;也可以通过 icon 插槽自定义图标。

vue
<script setup>
import { Bell } from '@element-plus/icons-vue'
</script>

<template>
  <el-alert title="Primary alert" type="primary" show-icon />
  <el-alert title="Error alert with custom icon" type="error" show-icon>
    <template #icon>
      <Bell />
    </template>
  </el-alert>
</template>

文字居中

设置 center 后,提示内容会水平居中,常用于短句提示。

vue
<el-alert title="Primary alert" type="primary" center show-icon />
<el-alert title="Success alert" type="success" center show-icon />
<el-alert title="Info alert" type="info" center show-icon />

文字描述

title 外,可以通过 description 添加更详细的辅助说明。描述文本过长时会自动换行。

vue
<el-alert
  title="With description"
  type="success"
  description="This is a description."
/>

带图标和描述

show-icon 可以和 description 一起使用,让提示层级更清晰。

vue
<el-alert
  title="Warning alert"
  type="warning"
  description="More text description"
  show-icon
/>

典型场景

Alert 常用于固定展示的规则、结果和风险信息,不适合作为自动消失的消息提示。

vue
<el-alert
  title="存在逾期风险"
  type="warning"
  description="该项目距离交付节点不足 3 天,请尽快确认排期。"
  show-icon
  :closable="false"
/>

API

Alert 属性

属性说明类型默认值
titleAlert 标题string''
typeAlert 类型primary / success / info / warning / errorinfo
description描述性文本string''
closable是否可以关闭booleantrue
center文字是否居中booleanfalse
close-text自定义关闭按钮文本string''
show-icon是否显示类型图标booleanfalse
effect主题样式light / darklight

Alert 事件

事件说明类型
close关闭 Alert 时触发(event: MouseEvent) => void

Alert 插槽

插槽说明
defaultAlert 内容描述
title自定义标题内容
icon自定义图标内容

使用提醒

  • Alert 用于页面内固定提示,不用于自动消失的轻量反馈;自动反馈优先使用 Message。
  • 单页内同一类提示要保持一致的 type 语义,避免 warningerror 混用。
  • 文案较长时使用 description,标题保持短句,方便用户快速扫描。

HOMEVISTA 设计规范