轻提示 Toast
用于交互提示、加载结果等场景。
使用
API安装使用
备注
小程序在机制上不允许动态插入 DOM。
因此,需要在外层先引入 <ti-toast id="titian-toast" /> 组件,再使用 js 方法展示该组件。
- index.json
 - index.js
 - index.wxml
 
code
{
  // 原生小程序
  "usingComponents": {
    "ti-toast": "@titian-design/weapp/toast/index"
  },
  // titan-cli 搭建的项目
  "usingComponents": {
    "ti-toast": "platform://titian-mp/ti-toast"
  }
}
// 原生小程序
import { $tiToast } from "@titian-design/weapp/index";
// titan-cli 搭建的项目
const { $tiToast } = requirePlatform("@titian-design/weapp").main;
<ti-toast id="titian-toast" />
用法示例
基本使用
ti-toast API
方法 Methods
| 方法名 | 说明 | 参数 | 返回值 | 
|---|---|---|---|
| $tiToast.success | 展示成功提示 | ToastOptions | string | - | 
| $tiToast.warn | 展示警告提示 | ToastOptions | string | - | 
| $tiToast.fail | 展示失败提示 | ToastOptions | string | - | 
| $tiToast.loading | 展示加载提示 | ToastOptions | string | - | 
| $tiToast.info | 展示文本 | ToastOptions | string | - | 
| $tiToast.clear | 清除提示 | - | - | 
ToastOptions 数据结构
| 名称 | 类型 | 必填 | 默认值 | 说明 | 备注 | 
|---|---|---|---|---|---|
| text | number | 否 | 100 | 文本 | |
| z-index | number | 否 | 30000 | z-index 层级 | |
| duration | number | 否 | 2000 | 展示时长 | - | 
| color | string | 否 | #fff | 颜色 | - | 
| icon | string | 否 | - | 轻提示 icon | - | 
| finished-callback | Function | 否 | 0 | 回调 | - | 
CSS 变量 CSS Variables
| CSS 变量 | 默认值 | 说明 | 
|---|---|---|
--toast-popup-mask-bg-color | 同 Popup 组件 --popup-mask-bg-color | - | 
--toast-popup-radius | theme.borderRadius.r2 | - | 
--toast-popup-box-bg-color | 同 Popup 组件 --popup-box-bg-color | - | 
--toast-bg-color | theme.color.gray.mask.800 | 容器背景色 | 
--toast-content-padding | theme.spacing.vertical.v4 theme.spacing.horizontal.h6 | icon模式下内容区域内边距 | 
theme.spacing.vertical.v5 theme.spacing.horizontal.h9 | 纯文字模式下内容区域内边距 | |
--toast-text-line-height | theme.lineHeight.multiline.t3 | icon 模式下文字行高 | 
theme.lineHeight.multiline.t6 | 纯文字模式下文字行度 | |
--toast-status-gap | theme.spacing.gap.g3 | 文字与Icon间距 | 
--toast-text-color | theme.color.gray.texticon.invert | - | 
--toast-text-font-size | theme.fontSize.t4 | icon模式文本区字号 | 
theme.fontSize.t6 | 纯文字模文本区字号 | |
--toast-text-font-weight | theme.fontWeight.regular | 纯文字模文本区字重 | 
--toast-icon-size | theme.fontSize.t16 | 图文模式下,icon 尺寸 |