# wx.showModal(Object object)

Displays the modal dialog box.

# Parameters

# Object object

Attribute Type Default Required Description
title string Yes Prompt title
content string Yes Prompt content
showCancel boolean true No Indicates whether to display the "Cancel" button
cancelText string 'Cancel' No The text of the "Cancel" button, not more than 4 characters
cancelColor string #000000 No The text color of the "Cancel" button, which must be a color string in hexadecimal format
confirmText string 'OK' No The text of the "OK "button, not more than 4 characters
confirmColor string #576B95 No The text color of the "OK" button, which must be a color string in hexadecimal format
success function No The callback function for a successful API call
fail function No Callback function for failed API call
complete function No Callback function used when API call completed (always executed whether call succeeds or fails)

# object.success callback function

# Parameters
# Object res
Property Type Description Minimum Version
confirm boolean When the value is "true", it indicates that the user tapped the "OK" button.
cancel boolean When the value is "true", it indicates that the user tapped the "Cancel" button. (this is used for Android system to distinguish whether "Mask" or "Cancel" is tapped) 1.1.0

# Sample Code

wx.showModal({
  title: 'Prompt',
  content: 'This is a modal pop-up window',
  success (res) {
    if (res.confirm) {
      console.log('"OK" is tapped')
    } else if (res.cancel) {
      console.log('"Cancel" is tapped')
    }
  }
})

# Notes

  • For Android 6.7.2 and below, when you tap Cancel or Mask, the callback will fail with the errMsg of "fail cancel".
  • For Android 6.7.2 & above and iOS, tapping Mask will not close the modal dialog box, so avoid using the "Cancel" branch to implement the business logic.
点击咨询小助手