dlt.showModal
Introduction
Displays a modal dialog box.
Parameters
Property | Required | Type | Default | Description | Minimum Version |
---|---|---|---|---|---|
title | No | string | The title of the modal dialog box. | ||
content | No | string | The content of the modal dialog box. | ||
showCancel | No | boolean | false | Whether to show the cancel button. | |
cancelText | No | string | Cancel | The text of the cancel button, up to 12 characters. | |
cancelColor | No | string | #92969E | The text color of the cancel button in hexadecimal format. | |
confirmText | No | string | Confirm | The text of the confirm button, up to 12 English characters. | |
confirmColor | No | string | #0081FF | The text color of the confirm button in hexadecimal format. | |
editable | No | boolean | false | Whether to show an input box. | 3.0.0 |
placeholderText | No | string | The placeholder text when displaying an input box. | 3.0.0 | |
success | No | function | Callback function for a successful API call. | ||
fail | No | function | Callback function for a failed API call. | ||
complete | No | function | Callback function that will be executed when the API call is complete (both successful and failed calls). |
success Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
success | string | true - successful |
confirm | boolean | When confirm is true, it means the user clicked the confirm button. |
cancel | boolean | When cancel is true, it means the user clicked the cancel button. |
content | string | When editable is true, it represents the text entered by the user. |
fail Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
success | string | false - failed |
Example Code
// pages/index/index.js
Page({
showModal() {
dlt.showModal({
title: "提示",
content: "这是一个模态弹窗",
success(res) {
if (res.confirm) {
console.log("用户点击确定");
} else if (res.cancel) {
console.log("用户点击取消");
}
},
});
},
});