# wx.showModal(Object object)

Promise 风格 调用:支持

小程序插件:支持,需要小程序基础库版本不低于 1.9.6

微信 Windows 版:支持

微信 Mac 版:支持

# 功能描述

显示模态对话框

# 参数

# Object object

属性 类型 默认值 必填 说明 最低版本
title string 提示的标题
content string 提示的内容
showCancel boolean true 是否显示取消按钮
cancelText string 取消 取消按钮的文字,最多 4 个字符
cancelColor string #000000 取消按钮的文字颜色,必须是 16 进制格式的颜色字符串
confirmText string 确定 确认按钮的文字,最多 4 个字符
confirmColor string #576B95 确认按钮的文字颜色,必须是 16 进制格式的颜色字符串
editable boolean false 是否显示输入框 2.17.1
placeholderText string 显示输入框时的提示文本 2.17.1
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数
complete function 接口调用结束的回调函数(调用成功、失败都会执行)

# object.success 回调函数

# 参数
# Object res
属性 类型 说明 最低版本
content string editable 为 true 时,用户输入的文本
confirm boolean 为 true 时,表示用户点击了确定按钮
cancel boolean 为 true 时,表示用户点击了取消(用于 Android 系统区分点击蒙层关闭还是点击取消按钮关闭) 1.1.0

# 示例代码

wx.showModal({
  title: '提示',
  content: '这是一个模态弹窗',
  success (res) {
    if (res.confirm) {
      console.log('用户点击确定')
    } else if (res.cancel) {
      console.log('用户点击取消')
    }
  }
})

# 注意

  • Android 6.7.2 以下版本,点击取消或蒙层时,回调 fail, errMsg 为 "fail cancel";
  • Android 6.7.2 及以上版本 和 iOS 点击蒙层不会关闭模态弹窗,所以尽量避免使用「取消」分支中实现业务逻辑
  • 自基础库 2.17.1 版本起,支持传入 editable 参数,显示带输入框的弹窗