- API 概览
- 开放能力
- 基础
- 渲染
- 设备
- 文件
- 位置
- 媒体
- 网络
- 游戏转发分享
- 实时语音
- 数据缓存
- 系统
- 广告
- 界面
- 支付
- Worker
tt.showModal收藏我的收藏
收藏
我的收藏基础库 1.0.0 开始支持本方法,这是一个异步方法。
显示模态弹窗。
前提条件 | 无 |
业务背景 | 无 |
使用限制 |
|
注意事项 | 无 |
相关教程 | 无 |
语法
tt.showModal(options)
参数说明
options 为 object 类型,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|---|
title | string | 否 | 标题 | 1.0.0 | |
content | string | 否 | 内容 | 1.0.0 | |
confirmText | string | 确定 | 否 | 确定按钮的文案,最多 4 个字符 | 1.0.0 |
showCancel | boolean | true | 否 | 是否显示取消按钮 | 1.0.0 |
cancelText | string | 取消 | 否 | 取消按钮的文案,最多 4 个字符 | 1.0.0 |
success | function | 否 | 接口调用成功的回调函数 | 1.0.0 | |
fail | function | 否 | 接口调用失败的回调函数 | 1.0.0 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 1.0.0 |
回调成功
object 类型,属性如下:
属性名 | 类型 | 说明 | 最低支持版本 |
---|---|---|---|
confirm | boolean | 是否点击了确定按钮 | 1.0.0 |
cancel | boolean | 是否点击了取消按钮 | 1.0.0 |
errMsg | string | "showModal:ok" | 1.0.0 |
回调失败
object 类型,属性如下:
属性名 | 类型 | 说明 | 最低支持版本 |
---|---|---|---|
errMsg | string | "showModal:fail " + 详细错误信息 | 1.0.0 |
扫码体验
请使用字节宿主APP扫码
代码示例
tt.showModal({
title: "请求获得定位权限",
content: "获得你的地理位置能够更好的为你推荐本地信息",
success(res) {
if (res.confirm) {
console.log("confirm, continued");
} else if (res.cancel) {
console.log("cancel, cold");
} else {
// what happend?
}
},
fail(res) {
console.log(`showModal调用失败`);
},
});
该文档是否有帮助?
点击纠错