Skip to content

t-notify

Notify 消息通知

组件介绍

消息通知组件,用于在页面上显示通知消息,支持配置消息类型、文本、持续时间等。

平台兼容

HarmonyH5AndroidiOS小程序UTS

基础用法

vue
<template>
  <view class="notify-demo">
    <t-button type="primary" @click="showSuccess">显示成功通知</t-button>
    <t-button type="error" @click="showError">显示错误通知</t-button>
    <t-button type="warning" @click="showWarning">显示警告通知</t-button>
    
    <t-notify ref="notifyRef"></t-notify>
  </view>
</template>

<script setup>
const notifyRef = ref(null);

function showSuccess() {
  notifyRef.value.add({
    type: 'success',
    text: '操作成功',
    duration: 3000,
    icon: 'check-circle'
  });
}

function showError() {
  notifyRef.value.add({
    type: 'error',
    text: '操作失败',
    duration: 3000,
    icon: 'close-circle'
  });
}

function showWarning() {
  notifyRef.value.add({
    type: 'warning',
    text: '请注意',
    duration: 3000,
    icon: 'warning'
  });
}
</script>

<style scoped>
.notify-demo {
  padding: 20rpx;
}
</style>

Props

属性名类型默认值说明可选值
sizeString""组件尺寸large, medium, small, mini
typeString""组件类型info, primary, error, warning, success
disabledBooleanfalse组件是否禁用true, false
hoverBooleanfalse是否有点击效果true, false
pathString""点击组件后跳转的页面路径-
effectString"normal"组件显示主题normal, dark, light, plain

Events

事件名说明回调参数
click点击时触发-
transitionend动画结束时触发-
initFinished组件初始化完成触发组件的节点信息
touchstart触摸开始时触发触摸事件对象
touchend触摸结束时触发触摸事件对象
touchmove触摸移动时触发触摸事件对象
touchcancel触摸取消时触发触摸事件对象

Methods

方法名说明参数返回值
add添加通知option: UTSJSONObject

Add 方法参数

属性名类型说明
typeString通知类型:info, primary, error, warning, success
textString通知文本内容
durationNumber显示持续时间,单位为毫秒
iconString通知图标名称
sizeString通知尺寸
colorString文字颜色
backgroundColorString背景颜色

Slots

插槽名说明
default内容插槽,用于自定义通知内容