移动端工具库
# 工具库使用
根据常见业务需求封装了一些公共方法。
# uni-clog
# uni-crypto
# uni-dict
# uni-error-handle
# uni-loading
# uni-modal
# uni-navbar
# uni-navigator
# uni-permission
# uni-request
# uni-rfid
# uni-scan
# uni-toast
uniapp的toast显示方法简化封装
# 使用
- 导入方法一:
<script>
import $toast from "@dme/uni-toast";
export default {
methods: {
showToast() {
// 用法一
$toast.toast("提示");
// 用法二
$toast.toast({
title: "提示"
})
},
showSuccessToast() {
$toast.success("成功");
},
showErrorToast() {
$toast.error("失败");
}
}
}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
- 导入方法二:
<script>
import { $toast, $success, $error } from "@dme/uni-toast";
export default {
methods: {
showToast() {
$toast("提示"); // 同上$toast.toast
},
showSuccessToast() {
$success("成功"); // 同上$toast.success
},
showErrorToast() {
$error("失败"); // 同上$toast.error
}
}
}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 说明
$toast、$success、$error接收的参数只有一个,类型为字符串或ToastType。
ToastT为对象类型,包含以下参数:
interface ToastT {
/** 持续时间超时后执行的方法 */
timeoutFunc?: Function;
/** 遮罩层 */
mask?: boolean;
/** 持续时间,单位毫秒 */
duration?: number;
/** 提示内容 */
title: string;
/** 图标 */
icon?: string;
/** 其他属性 */
[propName: string]: any;
}
type ToastType = UniApp.ShowToastOptions & ToastT;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
类型UniApp.ShowToastOptions (opens new window)请参考uni-app官方文档。
# 方法
| 名称 | 参数 | 说明 |
|---|---|---|
| $toast | (options: ToastType) | 默认提示 |
| $success | (options: ToastType) | 带成功图标的提示 |
| $error | (options: ToastType) | 带错误图标的提示 |
# 入参
| 名称 | 类型 | 说明 | 默认值 |
|---|---|---|---|
| timeoutFunc | Function | 倒计时结束回调 | - |
| mask | boolean | 遮罩层 | false |
| duration | number | 持续时间,单位毫秒 | 2000 |
| title | string | 提示内容 | 通知|成功|错误 |
# 注意
- uniapp中环境使用
- 可在vue2中使用
在线编辑 (opens new window)