Skip to content

引入

ts
import {
  showToast,
  showSuccess,
  showFail,
  clearToast,
  showLoading,
  dismissLoading,
  Toast
} from 't-comm';

// 不支持 tree-shaking 的项目
import {
  showToast,
  showSuccess,
  showFail,
  clearToast,
  showLoading,
  dismissLoading,
  Toast
} from 't-comm/lib/toast/index';

// 只支持 ESM 的项目
import {
  showToast,
  showSuccess,
  showFail,
  clearToast,
  showLoading,
  dismissLoading,
  Toast
} from 't-comm/es/toast/index';

showToast

描述

显示普通Toast

参数

参数名描述
text

文案

duration

显示时间,默认2秒

示例

ts
Toast.show('文本', 3000);

showSuccess

描述

显示成功样式Toast(toast带√样式)

参数

参数名描述
text

文案

duration

显示时间,默认2秒

示例

ts
Toast.showSuccess('文本', 3000);

showFail

描述

显示失败样式 Toast(toast带!样式)

参数

参数名描述
text

文案

duration

显示时间,默认2秒

示例

ts
Toast.showFail('文本', 3000);

clearToast

描述

清除(隐藏)上一个toast

参数

示例

ts
Toast.clear();

clearToast();

showLoading

描述

显示loading Toast

参数

参数名类型描述
optionsstring | object

配置,传递字符串时候为message

options.messagestring

内容

options.durationnumber

展示时长(ms),值为 0 时,toast 不会消失

options.forbidClickboolean

是否禁止背景点击

options.selectorstring

自定义选择器

示例

ts
Toast.showLoading('文本');

Toast.showLoading({
  message: '文本',
  zIndex: 1000,
});

dismissLoading

描述

隐藏loading toast

参数

示例

ts
Toast.dismissLoading();

Toast

描述

Toast 对象

参数

示例

ts
Toast.show('文本')