uni.showModal(options)
显示模态弹窗,可以只有一个确定按钮,也可以同时有确定和取消按钮。类似于一个API整合了 html 中:alert、confirm。
showModal 兼容性
Web | 微信小程序 | Android | Android uni-app x UTS 插件 | iOS | iOS uni-app x UTS 插件 | HarmonyOS |
4.0 | 4.41 | 3.91 | 3.91 | 4.11 | 4.11 | 4.61 |
参数
名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
options | ShowModalOptions | 是 | - | - | - |
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 | title | string | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| - | 4.41 | - | - | - |
| 提示的标题 | content | string | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| - | 4.41 | - | - | - |
| 提示的内容 | showCancel | boolean | 否 | true 是否显示取消按钮,默认为 true | - | | cancelText | string | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| - | 4.41 | - | - | - |
| 取消按钮的文字,默认为"取消" | cancelColor | string.ColorString | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| - | 4.41 | - | - | - |
| 取消按钮的文字颜色,默认为"#000000" | confirmText | string | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| - | 4.41 | - | - | - |
| 确定按钮的文字,默认为"确定" | confirmColor | string.ColorString | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| - | 4.41 | - | - | - |
| 确定按钮的文字颜色 | editable | boolean | 否 | false 是否显示输入框 | - | | placeholderText | string | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| - | 4.41 | - | - | - |
| 显示输入框时的提示文本 | success | (result: UniShowModalResult) => void | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| - | 4.41 | - | - | - |
| 接口调用成功的回调函数 | fail | (result: UniShowModalFail) => void | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| - | 4.41 | - | - | - |
| 接口调用失败的回调函数 | complete | (result: any) => void | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| - | 4.41 | - | - | - |
| 接口调用结束的回调函数(调用成功、失败都会执行) |
|
UniShowModalResult 的属性值
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
content | string | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| - | 4.41 | - | - | - |
| editable 为 true 时,用户输入的文本 |
cancel | boolean | 是 | - |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| - | 4.41 | - | - | - |
| 为 true 时,表示用户点击了取消(用于 Android 系统区分点击蒙层关闭还是点击取消按钮关闭) |
confirm | boolean | 是 | - |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| - | 4.41 | - | - | - |
| 为 true 时,表示用户点击了确定按钮 |
UniShowModalFail 的属性值
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
errCode | number | 是 | - | - | - |
errSubject | string | 是 | - | - | 统一错误主题(模块)名称 |
data | any | 否 | - | - | 错误信息中包含的数据 |
cause | Error | 否 | - | - | 源错误信息,可以包含多个错误,详见SourceError |
errMsg | string | 是 | - | - | - |
返回值
示例
hello uni-app x
参见
通用类型
GeneralCallbackResult
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
errMsg | string | 是 | - |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| - | 4.41 | - | - | - |
| 错误信息 |