跳到主要内容

showAlert

显示对话框 (alert 或者 action sheet)。

参数

interface AlertConfig {
title?: string;
message?: string;
preferredStyle?: "alert" | "actionSheet";
actions: AlertAction[];
}

interface AlertAction {
title?: string;
style?: "cancel" | "destructive";
key: string;
}

AlertConfig

名称类型必填默认值说明
titlestring标题
messagestring提示信息
preferredStyle"alert" or "actionSheet"alert样式
actionsAlertAction[]按钮配置

AlertAction

名称类型必填默认值说明
titlestring按钮文本
style"cancel" or "destructive"按钮样式
keystringalert按钮点击后,回调 key

返回值

名称类型说明
datastring?用户点击的按钮的 key,若取消,则为空

Example

import { showAlert } from "minip-bridge";

showAlert({
title: "default alert",
message: "message",
preferredStyle: "alert",
actions: [
{
title: "ok",
key: "ok",
},
{
title: "destructive",
key: "destructive",
style: "destructive",
},
{
title: "cancel",
key: "cancel",
style: "cancel",
},
],
}).then((res) => {
if (res.hasData()) {
console.log(`Selected ${res.data}`);
} else {
console.log("Canceled");
}
});