Modals
模态框 API 提供了调用原生模态窗口的方法,可用于显示警告提示、确认对话框、输入框以及操作表(Action Sheets)。
alert(...)
- 警告提示prompt(...)
- 输入提示confirm(...)
- 确认对话框showActions(...)
- 操作表- 接口定义
- 枚举
示例
import { Plugins, ActionSheetOptionStyle } from '@capacitor/core';
const { Modals } = Plugins;
async showAlert() {
let alertRet = await Modals.alert({
title: '停止',
message: '这是一个错误提示'
});
}
async showConfirm() {
let confirmRet = await Modals.confirm({
title: '确认',
message: '确定要按下红色按钮吗?'
});
console.log('确认结果', confirmRet);
}
async showPrompt() {
let promptRet = await Modals.prompt({
title: '你好',
message: '请问你叫什么名字?'
});
console.log('输入结果', promptRet);
}
async showActions() {
let promptRet = await Modals.showActions({
title: '图片操作',
message: '请选择要执行的操作',
options: [
{
title: '上传'
},
{
title: '分享'
},
{
title: '删除',
style: ActionSheetOptionStyle.Destructive
}
]
})
console.log('您的选择是', promptRet);
}
API
alert(...)
alert(options: AlertOptions) => Promise<void>
显示警告提示框
参数 | 类型 |
---|---|
options |
|
prompt(...)
prompt(options: PromptOptions) => Promise<PromptResult>
显示输入提示框
参数 | 类型 |
---|---|
options |
|
返回值:
Promise<PromptResult>
confirm(...)
confirm(options: ConfirmOptions) => Promise<ConfirmResult>
显示确认对话框
参数 | 类型 |
---|---|
options |
|
返回值:
Promise<ConfirmResult>
showActions(...)
showActions(options: ActionSheetOptions) => Promise<ActionSheetResult>
显示操作表(Action Sheet)模态框,提供多个选项供用户选择。
参数 | 类型 |
---|---|
options |
|
返回值:
Promise<ActionSheetResult>
Interfaces
AlertOptions
属性 | 类型 |
---|---|
title | string |
message | string |
buttonTitle | string |
PromptResult
属性 | 类型 |
---|---|
value | string |
cancelled | boolean |
PromptOptions
属性 | 类型 |
---|---|
title | string |
message | string |
okButtonTitle | string |
cancelButtonTitle | string |
inputPlaceholder | string |
inputText | string |
ConfirmResult
属性 | 类型 |
---|---|
value | boolean |
ConfirmOptions
属性 | 类型 |
---|---|
title | string |
message | string |
okButtonTitle | string |
cancelButtonTitle | string |
ActionSheetResult
属性 | 类型 |
---|---|
index | number |
ActionSheetOptions
属性 | 类型 | 描述 |
---|---|---|
title | string | |
message | string | 仅限 iOS |
options | ActionSheetOption[] | 操作选项列表 |
ActionSheetOption
属性 | 类型 | 描述 |
---|---|---|
title | string | 选项标题 |
style |
| 样 式类型 |
icon | string | Web 图标(使用 ionicon 命名规范) |
Enums类型
ActionSheetOptionStyle
枚举值 | 值 |
---|---|
Default | "DEFAULT" |
Destructive | "DESTRUCTIVE" |
Cancel | "CANCEL" |