codecamp

tt.showModal

从基础库 1.0.0 开始支持。

显示模态弹窗。


参数

Object object

属性类型默认值必填说明
titlestring标题
contentstring内容
confirmTextstring确定确定按钮的文案,最多 4 个字符
showCancelbooleantrue是否显示取消按钮
cancelTextstring取消取消按钮的文案,最多 4 个字符
successfunction接口调用成功后的回调函数
failfunction接口调用失败后的回调函数
completefunction接口调用结束后的回调函数(调用成功、失败都会执行)

success 返回参数说明

Object 类型,属性如下:

属性类型说明
confirmboolean是否点击了确定按钮
cancelboolean是否点击了取消按钮


代码示例

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


Bug & Tip

  • 暂不支持confirmColor和cancelColor参数。
  • title的长度限制:android 端限制为 1 行,每行约 13 个汉字。iOS 端限制为 3 行,每行约 17 个汉字。
  • content的长度限制:android 端没有限制,Modal 最高为屏幕高度,内容滚动;iOS 端限制为 3 行,每行约 17 个汉字。
  • 输入参数的title和content不可同时为空。
tt.showToast
tt.showLoading
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

无标题目录

无标题文章

无标题文章

无标题文章

无标题文章

无标题文章

无标题文章

无标题文章

无标题文章

无标题文章

无标题文章

无标题文章

无标题文章

无标题文章

无标题文章

无标题目录

无标题文章

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }