Skip to content

Notify 消息通知

基础用法

html
<script setup lang="ts">
import { ref } from 'vue'
import { NotifyInst, NotifyOptions } from 'ano-ui'

const notify = ref<NotifyInst>()

function showNotify(options: NotifyOptions) {
  notify.value?.show(options)
}
</script>

<template>
  <ANotify ref="notify" />
  <AButton @click="showNotify({ title: '标题', message: '这是一个消息通知' })">
    展示消息通知
  </AButton>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { NotifyInst, NotifyOptions } from 'ano-ui'

const notify = ref<NotifyInst>()

function showNotify(options: NotifyOptions) {
  notify.value?.show(options)
}
</script>

<template>
  <ANotify ref="notify" />
  <AButton @click="showNotify({ title: '标题', message: '这是一个消息通知' })">
    展示消息通知
  </AButton>
</template>

消息通知类型&图标

html
<script setup lang="ts">
import { ref } from 'vue'
import { NotifyInst, NotifyOptions } from 'ano-ui'

const notify = ref<NotifyInst>()

function showNotify(options: NotifyOptions) {
  notify.value?.show(options)
}
</script>

<template>
  <ANotify ref="notify" />

  <ACellGroup arrow divider inset>
    <ACell title="主要通知" @click="showNotify({ type: 'primary', showIcon: true, message: '通知内容' })" />
    <!-- <ACell title="信息通知" @click="showNotify({ type: 'info', showIcon: true, message: '通知内容' })" /> -->
    <ACell title="成功通知" @click="showNotify({ type: 'success', showIcon: true, message: '通知内容' })" />
    <ACell title="警告通知" @click="showNotify({ type: 'warning', showIcon: true, message: '通知内容' })" />
    <ACell title="危险通知" @click="showNotify({ type: 'danger', showIcon: true, message: '通知内容' })" />
  </ACellGroup>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { NotifyInst, NotifyOptions } from 'ano-ui'

const notify = ref<NotifyInst>()

function showNotify(options: NotifyOptions) {
  notify.value?.show(options)
}
</script>

<template>
  <ANotify ref="notify" />

  <ACellGroup arrow divider inset>
    <ACell title="主要通知" @click="showNotify({ type: 'primary', showIcon: true, message: '通知内容' })" />
    <!-- <ACell title="信息通知" @click="showNotify({ type: 'info', showIcon: true, message: '通知内容' })" /> -->
    <ACell title="成功通知" @click="showNotify({ type: 'success', showIcon: true, message: '通知内容' })" />
    <ACell title="警告通知" @click="showNotify({ type: 'warning', showIcon: true, message: '通知内容' })" />
    <ACell title="危险通知" @click="showNotify({ type: 'danger', showIcon: true, message: '通知内容' })" />
  </ACellGroup>
</template>

消息通知位置

Notify 默认渲染在屏幕正中位置,通过 position 属性可以控制 Notify 展示的位置。

html
<script setup lang="ts">
import { ref } from 'vue'
import { NotifyInst, NotifyOptions } from 'ano-ui'

const notify = ref<NotifyInst>()

function showNotify(options: NotifyOptions) {
  notify.value?.show(options)
}
</script>

<template>
  <ANotify ref="notify" />

  <ACellGroup arrow divider inset>
    <ACell title="默认顶部" @click="showNotify({ position: 'default', message: '通知内容' })" />
    <ACell title="上方" @click="showNotify({ position: 'top', message: '通知内容' })" />
    <ACell title="左上角" @click="showNotify({ position: 'top-left', message: '通知内容' })" />
    <ACell title="右上角" @click="showNotify({ position: 'top-right', message: '通知内容' })" />
    <ACell title="下方" @click="showNotify({ position: 'bottom', message: '通知内容' })" />
    <ACell title="左下角" @click="showNotify({ position: 'bottom-left', message: '通知内容' })" />
    <ACell title="右下角" @click="showNotify({ position: 'bottom-right', message: '通知内容' })" />
  </ACellGroup>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { NotifyInst, NotifyOptions } from 'ano-ui'

const notify = ref<NotifyInst>()

function showNotify(options: NotifyOptions) {
  notify.value?.show(options)
}
</script>

<template>
  <ANotify ref="notify" />

  <ACellGroup arrow divider inset>
    <ACell title="默认顶部" @click="showNotify({ position: 'default', message: '通知内容' })" />
    <ACell title="上方" @click="showNotify({ position: 'top', message: '通知内容' })" />
    <ACell title="左上角" @click="showNotify({ position: 'top-left', message: '通知内容' })" />
    <ACell title="右上角" @click="showNotify({ position: 'top-right', message: '通知内容' })" />
    <ACell title="下方" @click="showNotify({ position: 'bottom', message: '通知内容' })" />
    <ACell title="左下角" @click="showNotify({ position: 'bottom-left', message: '通知内容' })" />
    <ACell title="右下角" @click="showNotify({ position: 'bottom-right', message: '通知内容' })" />
  </ACellGroup>
</template>

API

NotifyOptions 数据结构

参数说明类型默认值
message消息内容string-
type类型,可选值为 primary success warning dangerstringprimary
position位置,可选值为 default top top-left top-right bottom bottom-left bottom-rightstringdefault
duration展示时长(ms),值为 0 时,notify 不会消失number3000
showIcon是否显示图标booleanfalse
showClose是否显示关闭按钮booleanfalse

Events

事件名说明回调参数

Slots

名称说明
default自定义内容
icon自定义图标

MIT Licensed