抖音开放平台Logo
控制台

tt.showModal
收藏
我的收藏

基础库 1.0.0 开始支持本方法,这是一个异步方法。

显示模态弹窗。

前提条件
业务背景
使用限制
  • 暂不支持 confirmColor 和 cancelColor 参数。
  • title 的长度限制:
    • android 端限制为 1 行,每行约 13 个汉字。
    • iOS 端限制为 3 行,每行约 17 个汉字。
  • content 的长度限制:
    • android 端没有限制,Modal 最高为屏幕高度,内容滚动;
    • iOS 端限制为 3 行,每行约 17 个汉字。
  • 输入参数的 title 和 content 不可同时为空。
注意事项
相关教程

语法

tt.showModal(options)

参数说明

options 为 object 类型,属性如下:

属性名类型默认值必填说明最低支持版本
titlestring

标题

1.0.0
contentstring

内容

1.0.0
confirmTextstring确定

确定按钮的文案,最多 4 个字符

1.0.0
showCancelbooleantrue

是否显示取消按钮

1.0.0
cancelTextstring取消

取消按钮的文案,最多 4 个字符

1.0.0
successfunction
接口调用成功的回调函数
1.0.0
failfunction
接口调用失败的回调函数
1.0.0
completefunction
接口调用结束的回调函数(调用成功、失败都会执行)
1.0.0

回调成功

object 类型,属性如下:

属性名类型说明最低支持版本
confirmboolean

是否点击了确定按钮

1.0.0
cancelboolean

是否点击了取消按钮

1.0.0
errMsgstring

"showModal:ok"

1.0.0

回调失败

object 类型,属性如下:

属性名类型说明最低支持版本
errMsgstring

"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调用失败`);
  },
});