Skip to content

Alert 提示

用于页面中展示重要的提示信息。

基础用法

Alert 组件不属于浮层元素,不会自动消失或关闭。

Alert 组件提供四种类型,由 type 属性指定,为 success | warning | danger | info , 默认值为 info

<template>
  <h2>通过 slot 传入内容</h2>
  <div style="max-width: 600px">
    <er-alert type="success">Success alert</er-alert>
    <er-alert type="info">Info alert</er-alert>
    <er-alert type="warning">Warning alert</er-alert>
    <er-alert type="danger">Error alert</er-alert>
  </div>
  <h2>通过 prop 传入内容</h2>
  <div style="max-width: 600px">
    <er-alert type="success" title="Success alert" />
    <er-alert type="info" title="Info alert" />
    <er-alert type="warning" title="Warning alert" />
    <er-alert type="danger" title="Error alert" />
  </div>
</template>

主题

通过设置 effect 属性来改变主题(light|dark),默认为 light

<template>
  <div style="max-width: 600px">
    <er-alert title="Success Alert" type="success" effect="dark" />
    <er-alert title="Info Alert" type="info" effect="dark" />
    <er-alert title="Warning Alert" type="warning" effect="dark" />
    <er-alert title="Error Alert" type="danger" effect="dark" />
  </div>
</template>

不可关闭

可以设置 Alert 组件是否为可关闭状态, closable 属性决定 Alert 组件是否可关闭, 该属性接受一个 Boolean,默认为 false

<script setup>
import { ErMessage } from "eric-ui";

function handleClose() {
  ErMessage.info("close callback");
}
</script>
<template>
  <div class="basic block">
    <er-alert title="Unclosable alert" type="success" :closable="false" />
    <er-alert title="Alert with callback" type="warning" @close="handleClose" />
  </div>
</template>

展示图标

通过设置 show-icon 属性来显示 Alert 的 icon,这能更有效地向用户展示你的显示意图。

<template>
  <div style="max-width: 600px">
    <er-alert title="Success alert" type="success" show-icon />
    <er-alert title="Info alert" type="info" show-icon />
    <er-alert title="Warning alert" type="warning" show-icon />
    <er-alert title="Error alert" type="danger" show-icon />
  </div>
</template>

文字居中

使用 center 属性来让文字水平居中。

<template>
  <div style="max-width: 600px">
    <er-alert title="Success alert" type="success" center show-icon />
    <er-alert title="Info alert" type="info" center show-icon />
    <er-alert title="Warning alert" type="warning" center show-icon />
    <er-alert title="Error alert" type="danger" center show-icon />
  </div>
</template>

文字描述

除了必填的 title 属性外,你可以设置 description 属性来帮助你更好地介绍,我们称之为辅助性文字。

<template>
  <div style="max-width: 600px">
    <er-alert
      title="With description"
      type="success"
      description="This is a description."
    />
  </div>
</template>

带图标和描述

<template>
  <div style="max-width: 600px">
    <er-alert
      title="Success alert"
      type="success"
      description="More text description"
      show-icon
    />
    <er-alert
      title="Info alert"
      type="info"
      description="More text description"
      show-icon
    />
    <er-alert
      title="Warning alert"
      type="warning"
      description="More text description"
      show-icon
    />
    <er-alert
      title="Error alert"
      type="danger"
      description="More text description"
      show-icon
    />
  </div>
</template>

Alert API

Props

NameDescriptionTypeDefault
titleAlert 标题string
typeAlert 类型enum - 'success'| 'warning'| 'danger'| 'info'info
description描述性文本string
closable是否可以关闭booleantrue
center文字是否居中booleanfalse
show-icon是否展示图标booleanfalse
effect主题样式enum - 'light'| 'dark'\light

Events

NameDescriptionType
close关闭 Alert 时触发的事件(event: MouseEvent)=> void

Slots

NameDescription
default默认插槽,用于设置 Alert 的内容描述
title标题的内容

Expose

NameDescriptionType
open打开 Alert() => void
close关闭 Alert() => void