t-notify
Notify 消息通知
组件介绍
消息通知组件,用于在页面上显示通知消息,支持配置消息类型、文本、持续时间等。
平台兼容
| Harmony | H5 | Android | iOS | 小程序 | 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
| 属性名 | 类型 | 默认值 | 说明 | 可选值 |
|---|---|---|---|---|
| size | String | "" | 组件尺寸 | large, medium, small, mini |
| type | String | "" | 组件类型 | info, primary, error, warning, success |
| disabled | Boolean | false | 组件是否禁用 | true, false |
| hover | Boolean | false | 是否有点击效果 | true, false |
| path | String | "" | 点击组件后跳转的页面路径 | - |
| effect | String | "normal" | 组件显示主题 | normal, dark, light, plain |
Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
| click | 点击时触发 | - |
| transitionend | 动画结束时触发 | - |
| initFinished | 组件初始化完成触发 | 组件的节点信息 |
| touchstart | 触摸开始时触发 | 触摸事件对象 |
| touchend | 触摸结束时触发 | 触摸事件对象 |
| touchmove | 触摸移动时触发 | 触摸事件对象 |
| touchcancel | 触摸取消时触发 | 触摸事件对象 |
Methods
| 方法名 | 说明 | 参数 | 返回值 |
|---|---|---|---|
| add | 添加通知 | option: UTSJSONObject | 无 |
Add 方法参数
| 属性名 | 类型 | 说明 |
|---|---|---|
| type | String | 通知类型:info, primary, error, warning, success |
| text | String | 通知文本内容 |
| duration | Number | 显示持续时间,单位为毫秒 |
| icon | String | 通知图标名称 |
| size | String | 通知尺寸 |
| color | String | 文字颜色 |
| backgroundColor | String | 背景颜色 |
Slots
| 插槽名 | 说明 |
|---|---|
| default | 内容插槽,用于自定义通知内容 |