For AI agents: the complete documentation index is available at https://docs.halo.run/llms.txt, the full documentation bundle is available at https://docs.halo.run/llms-full.txt, and this page is available as Markdown at https://docs.halo.run/developer-guide/plugin/api-reference/ui/base-components/alert.md.

VAlert 提示

VAlert 用于在页面内展示需要用户注意的信息,提供比 Toast 更持久、比 Dialog 更轻量的提示方式。

引入

import { VAlert } from "@halo-dev/components";

示例

基础用法

<script lang="ts" setup>
import { VAlert } from "@halo-dev/components";
</script>

<template>
  <VAlert
    type="info"
    title="内容已保存为草稿"
    description="发布前仍可继续编辑,草稿会保留最近一次保存的内容。"
  />
</template>

不同类型

<script lang="ts" setup>
import { VAlert, VSpace } from "@halo-dev/components";
</script>

<template>
  <VSpace direction="column" align="stretch">
    <VAlert
      type="success"
      title="站点配置已更新"
      description="新的 SEO 和缓存设置已经生效。"
    />
    <VAlert
      type="info"
      title="发现新版本"
      description="Halo 2.27.0 已发布,包含若干问题修复。"
    />
    <VAlert
      type="warning"
      title="插件需要重新加载"
      description="检测到插件配置发生变化,重新加载后才能应用到前台页面。"
    />
    <VAlert
      type="error"
      title="同步失败"
      description="远程内容源暂时不可用,请检查网络连接后重试。"
    />
  </VSpace>
</template>

带操作按钮

<script lang="ts" setup>
import { VAlert, VButton, VSpace } from "@halo-dev/components";
</script>

<template>
  <VAlert type="warning" title="存在未保存的更改">
    <template #actions>
      <VSpace spacing="sm">
        <VButton size="sm" type="primary">保存</VButton>
        <VButton size="sm">放弃</VButton>
      </VSpace>
    </template>
  </VAlert>
</template>

不可关闭

<script lang="ts" setup>
import { VAlert } from "@halo-dev/components";
</script>

<template>
  <VAlert
    type="default"
    title="只读模式"
    description="当前账号没有修改权限。"
    :closable="false"
  />
</template>

监听关闭事件

VAlert 不会自行隐藏,需要在 close 事件中控制显示状态。

<script lang="ts" setup>
import { ref } from "vue";
import { VAlert, VButton } from "@halo-dev/components";

const visible = ref(true);
</script>

<template>
  <VSpace direction="column" align="start">
    <VAlert
      v-if="visible"
      title="点击右侧关闭按钮可关闭此提示"
      @close="visible = false"
    />
    <VButton v-if="!visible" @click="visible = true">重新显示</VButton>
  </VSpace>
</template>

Props

属性类型默认值说明
type"default" | "success" | "info" | "warning" | "error""default"提示类型,决定图标和配色
titlestring""标题
descriptionstring""描述内容
closablebooleantrue是否显示关闭按钮

Emits

事件参数说明
close-点击关闭按钮时触发,不会自动隐藏提示

Slots

插槽说明
icon自定义图标,默认根据 type 显示对应图标
title自定义标题
description自定义描述内容
actions操作区域,显示在描述下方