confirm
显示模态对话框。
支持
安装
$ npm install @uni/confirm --save
or
$ npm install @uni/apis --save
示例
import confirm from '@uni/confirm';
confirm({
title: '提示',
content: '这是一个模态弹窗',
success (res) {
if (res.confirm) {
console.log('用户点击确定')
} else if (res.cancel) {
console.log('用户点击取消')
}
}
});
// promise
confirm({
title: '提示',
content: '这是一个模态弹窗'
}).then(res => {
if (res.confirm) {
console.log('用户点击确定')
} else if (res.cancel) {
console.log('用户点击取消')
}
});
你也可以从大包引入:
import { confirm } from '@uni/apis';
方法
confirm(options)
参数
成员 | 类型 | 描述 | 必选 | 默认值 |
---|---|---|---|---|
options |
object |
- | ||
options.title |
string |
提示的标题 | ✘ | - |
options.content |
string |
提示的内容 | ✘ | - |
options.confirmText |
string |
确认按钮的文字,最多 4 个字符 | ✘ | "确定" |
options.cancelText |
string |
取消按钮的文字,最多 4 个字符 | ✘ | "取消" |
options.success |
Function |
成功的回调 | ✘ | - |
options.fail |
Function |
失败的回调 | ✘ | - |
options.complete |
Function |
结束的回调 (调用成功、失败都会执行) | ✘ | - |
差异化参数
成员 | 类型 | 描述 | 必选 | 默认值 | 支持度 |
---|---|---|---|---|---|
options.showCancel | boolean |
是否显示取消按钮 | ✘ | true | |
options.cancelColor | string |
取消按钮的文字颜色,必须是 16 进制格式的颜色字符串 | ✘ | #000000 | |
options.confirmColor | string |
确认按钮的文字颜色,必须是 16 进制格式的颜色字符串 | ✘ | #576B95 |
返回
成员 | 类型 | 描述 | 支持 |
---|---|---|---|
confirm | boolean |
为 true 时,表示用户点击了确定按钮 | |
cancel | boolean |
为 true 时,表示用户点击了取消(用于 Android 系统区分点击蒙层关闭还是点击取消按钮关闭),微信和字节端特有 |