You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.4 KiB

---
order: 1
title:
zh-CN: 异步关闭
en-US: Asynchronously close
---
## zh-CN
点击确定后异步关闭对话框,例如提交表单。
## en-US
Asynchronously close a modal dialog when a user clicked OK button, for example,
you can use this pattern when you submit a form.
````jsx
import { Modal, Button } from 'antd';
class App extends React.Component {
state = {
ModalText: 'Content of the modal dialog',
visible: false,
}
showModal = () => {
10 years ago
this.setState({
visible: true,
10 years ago
});
}
handleOk = () => {
this.setState({
ModalText: 'The modal dialog will be closed after two seconds',
confirmLoading: true,
});
setTimeout(() => {
10 years ago
this.setState({
visible: false,
confirmLoading: false,
10 years ago
});
}, 2000);
}
handleCancel = () => {
console.log('Clicked cancel button');
this.setState({
visible: false,
});
}
render() {
return (
<div>
<Button type="primary" onClick={this.showModal}>Open a modal dialog</Button>
<Modal title="Title of the modal dialog"
visible={this.state.visible}
onOk={this.handleOk}
confirmLoading={this.state.confirmLoading}
onCancel={this.handleCancel}
>
<p>{this.state.ModalText}</p>
</Modal>
</div>
);
}
}
ReactDOM.render(<App />, mountNode);
````