Skip to content

Notification 通知

悬浮出现在页面角落,显示全局的通知提醒消息。

基础用法

<script setup lang="ts">
import { h } from "vue";
import { hyNotification } from "hy-element";

function openNotify1() {
  (hyNotification as Function)({
    title: "Title",
    message: h("i", { style: "color:teal" }, "This is a remidhy"),
    position:'bottom-right'
  });
}

function openNotify2() {
  (hyNotification as Function)({
    title: "Prompt",
    message: "This is a message that does not auto close",
    duration: 0,
    position:'top-left'
  });
}
</script>

<template>
  <hy-button @click="openNotify1" plain>Closes automatically</hy-button>
  <hy-button @click="openNotify2" plain>Won't closes automatically</hy-button>
</template>

不同类型的通知

提供了四种不同类型的提醒框:successwarninginfoerror (danger 效果和 error 相同)。

<script lang="ts" setup>
import { hyNotification } from "hy-element";

const open1 = () => {
  (hyNotification as Function)({
    title: "Success",
    message: "This is a success message",
    type: "success",
  });
};

const open2 = () => {
  (hyNotification as Function)({
    title: "Warning",
    message: "This is a warning message",
    type: "warning",
  });
};

const open3 = () => {
  (hyNotification as Function)({
    title: "Info",
    message: "This is an info message",
    type: "info",
  });
};

const open4 = () => {
  (hyNotification as Function)({
    title: "hyror",
    message: "This is an hyror message",
    type: "danghy",
  });
};
</script>

<template>
  <hy-button plain @click="open1"> Success </hy-button>
  <hy-button plain @click="open2"> Warning </hy-button>
  <hy-button plain @click="open3"> Info </hy-button>
  <hy-button plain @click="open4"> hyror </hy-button>
</template>

隐藏关闭按钮

可以通过设置 closable 属性来隐藏关闭按钮。

<script lang="ts" setup>
import { hyNotification } from 'hy-element'

const open = () => {
    ((hyNotification as any).success)({
        title: 'Info',
        message: 'This is a message without close button',
        showClose: false,
    })
}
</script>

<template>
    <hy-button plain @click="open"> Hide close button </hy-button>
</template>

全局方法

通过全局方法 $notify 调用,可以弹出通知。

单独引用

typescript
import { hyNotification } from "hy-element";

Notification API

Options

NameDescriptionTypeDefault
title标题string-
message通知正文内容string | VNode-
type通知的类型enum - info | success | warning | error | dangerinfo
icon自定义图标string-
duration显示时间number3000
showClose是否显示关闭按钮booleantrue
onClose关闭时的回调函数() => void-
onClick点击时的回调函数() => void-
offset偏移number20

Handler

NameDescriptionType
close关闭 Notification() => void