// extends.js
// 设置默认参数
const toast = ( { title = '数据加载中...', icon = 'none', duration = 2000, mask = true } = {} ) => {
wx.showToast({
title,
icon,
duration,
mask
})
}
// 将封装的模块挂载到 wx 全局对象身上
wx.toast = toast
- 使用
// app.js 或 其他 js 文件
import './utils/extendApi'
// 消息提示框
wx.toast({ title: '数据加载成功', icon: 'success' })