mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-23 06:58:33 +08:00
40 lines
913 B
Markdown
40 lines
913 B
Markdown
---
|
|
order: 5
|
|
title:
|
|
zh-CN: 确认对话框
|
|
en-US: Confirmation modal dialog
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
使用 `confirm()` 可以快捷地弹出确认框。onCancel/onOk 返回 promise 可以延迟关闭
|
|
|
|
## en-US
|
|
|
|
To use `confirm()` to popup confirmation modal dialog. Let onCancel/onOk function return a promise object to
|
|
delay closing the dialog.
|
|
|
|
````__react
|
|
import { Modal, Button } from 'antd';
|
|
const confirm = Modal.confirm;
|
|
|
|
function showConfirm() {
|
|
confirm({
|
|
title: 'Want to delete these items?',
|
|
content: 'When clicked the OK button, this dialog will be closed after 1 second',
|
|
onOk() {
|
|
return new Promise((resolve, reject) => {
|
|
setTimeout(Math.random() > 0.5 ? resolve : reject, 1000);
|
|
}).catch(() => console.log('Oops errors!'));
|
|
},
|
|
onCancel() {},
|
|
});
|
|
}
|
|
|
|
ReactDOM.render(
|
|
<Button onClick={showConfirm}>
|
|
Confirmation modal dialog
|
|
</Button>
|
|
, mountNode);
|
|
````
|