Skip to content

Toast 消息提示组件

Toast 组件主要用于消息通知、加载提示、操作结果提示等醒目提示效果,我们为其提供了多种丰富的API。

温馨提示

本项目参考了 uView-Plus 开源项目的组件开发方式,基于 Vue 3 和 TypeScript 实现了自定义组件。目前该组件仍处于测试阶段。
感谢 uView-Plus 开源项目及其团队成员的贡献,他们的组件开发思路为本项目提供了宝贵地参考。如果需要了解更多组件开发细节,可以参考uView-Plus的 toast组件 的代码实现。

注意

由于uni中无法通过js创建元素,所以需要在页面中调用toast组件,再通过ref开启

平台差异说明

APP(vue)H5微信小程序

基本使用示例

html
<!-- 全局使用 -->
<hy-toast ref="hyToastRef"></hy-toast>
<!-- 单个组件引入 -->
<HyToast ref="hyToastRef"></HyToast>
ts
import {HyToast} from "hy-app"
import {onMounted, ref} from "vue";

const hyToastRef = ref();

onMounted(() => {
    hyToastRef.value.show({
      message: "我是默认提示信息",
      type: "primary",
      icon: true,
      duration: 1000,
      position: "bottom",
    });
})

API(params)

参数说明类型默认值
message显示的文本string-
type主题类型error|warning|success|primary|infoinfo
icon图标,或者绝对路径的图片string | booleanfalse
loading是否加载中booleanfalse
overlay是否防止触摸穿透booleantrue
positiontoast出现的位置top|center|bottomcenter
params跳转的参数Object-
duration展示时间,单位ms, 值为-1时不自动关闭number2000
complete执行完后的回调函数Function-

Methods

事件名说明参数
show显示toast,如需一进入页面就显示toast,请在onReady生命周期调用params: 见上方说明
00:46