You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.2 KiB
Markdown
61 lines
1.2 KiB
Markdown
10 years ago
|
# 异步关闭
|
||
|
|
||
|
- order: 1
|
||
|
|
||
9 years ago
|
点击确定后异步关闭对话框,例如提交表单。
|
||
10 years ago
|
|
||
|
---
|
||
|
|
||
|
````jsx
|
||
|
var Modal = antd.Modal;
|
||
9 years ago
|
var Button = antd.Button;
|
||
|
|
||
10 years ago
|
var ModalText = '对话框的内容';
|
||
|
|
||
|
var Test = React.createClass({
|
||
|
getInitialState() {
|
||
|
return {
|
||
10 years ago
|
ModalText: '对话框的内容',
|
||
10 years ago
|
visible: false
|
||
10 years ago
|
};
|
||
|
},
|
||
10 years ago
|
showModal() {
|
||
10 years ago
|
this.setState({
|
||
10 years ago
|
visible: true
|
||
10 years ago
|
});
|
||
10 years ago
|
},
|
||
|
handleOk() {
|
||
|
this.setState({
|
||
9 years ago
|
ModalText: '对话框将在两秒后关闭',
|
||
|
confirmLoading: true
|
||
10 years ago
|
});
|
||
10 years ago
|
setTimeout(() => {
|
||
10 years ago
|
this.setState({
|
||
9 years ago
|
visible: false,
|
||
|
confirmLoading: false
|
||
10 years ago
|
});
|
||
10 years ago
|
}, 2000);
|
||
10 years ago
|
},
|
||
|
handleCancel() {
|
||
|
console.log('点击了取消');
|
||
10 years ago
|
this.setState({
|
||
|
visible: false
|
||
|
});
|
||
10 years ago
|
},
|
||
|
render() {
|
||
|
return <div>
|
||
9 years ago
|
<Button type="primary" onClick={this.showModal}>显示对话框</Button>
|
||
10 years ago
|
<Modal title="对话框标题"
|
||
10 years ago
|
visible={this.state.visible}
|
||
10 years ago
|
onOk={this.handleOk}
|
||
9 years ago
|
confirmLoading={this.state.confirmLoading}
|
||
10 years ago
|
onCancel={this.handleCancel}>
|
||
|
<p>{this.state.ModalText}</p>
|
||
|
</Modal>
|
||
|
</div>;
|
||
|
}
|
||
|
});
|
||
|
|
||
9 years ago
|
ReactDOM.render(<Test/> , document.getElementById('components-modal-demo-async'));
|
||
10 years ago
|
````
|