2015-06-12 17:11:32 +08:00
|
|
|
# 异步关闭
|
|
|
|
|
|
|
|
- order: 1
|
|
|
|
|
2015-06-12 17:37:39 +08:00
|
|
|
点击确定后异步关闭对话框。
|
2015-06-12 17:11:32 +08:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
````jsx
|
|
|
|
var Modal = antd.Modal;
|
2015-10-08 15:13:04 +08:00
|
|
|
var Button = antd.Button;
|
|
|
|
|
2015-06-12 17:11:32 +08:00
|
|
|
var ModalText = '对话框的内容';
|
|
|
|
|
|
|
|
var Test = React.createClass({
|
|
|
|
getInitialState() {
|
|
|
|
return {
|
2015-06-12 23:31:44 +08:00
|
|
|
ModalText: '对话框的内容',
|
2015-06-14 13:20:35 +08:00
|
|
|
visible: false
|
2015-06-12 17:11:32 +08:00
|
|
|
};
|
|
|
|
},
|
2015-08-18 12:26:19 +08:00
|
|
|
showModal() {
|
2015-06-12 23:31:44 +08:00
|
|
|
this.setState({
|
2015-08-18 12:26:19 +08:00
|
|
|
visible: true
|
2015-06-12 23:31:44 +08:00
|
|
|
});
|
2015-06-12 17:11:32 +08:00
|
|
|
},
|
|
|
|
handleOk() {
|
|
|
|
this.setState({
|
|
|
|
ModalText: '对话框将在两秒后关闭'
|
|
|
|
});
|
2015-08-25 17:08:43 +08:00
|
|
|
setTimeout(() => {
|
2015-06-12 23:31:44 +08:00
|
|
|
this.setState({
|
2015-06-14 13:20:35 +08:00
|
|
|
visible: false
|
2015-06-12 23:31:44 +08:00
|
|
|
});
|
2015-08-25 17:08:43 +08:00
|
|
|
}, 2000);
|
2015-06-12 17:11:32 +08:00
|
|
|
},
|
|
|
|
handleCancel() {
|
|
|
|
console.log('点击了取消');
|
2015-09-08 12:38:21 +08:00
|
|
|
this.setState({
|
|
|
|
visible: false
|
|
|
|
});
|
2015-06-12 17:11:32 +08:00
|
|
|
},
|
|
|
|
render() {
|
|
|
|
return <div>
|
2015-10-08 15:13:04 +08:00
|
|
|
<Button type="primary" onClick={this.showModal}>显示对话框</Button>
|
2015-07-22 17:32:22 +08:00
|
|
|
<Modal title="对话框标题"
|
2015-06-12 23:31:44 +08:00
|
|
|
visible={this.state.visible}
|
2015-06-12 17:11:32 +08:00
|
|
|
onOk={this.handleOk}
|
|
|
|
onCancel={this.handleCancel}>
|
|
|
|
<p>{this.state.ModalText}</p>
|
|
|
|
</Modal>
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-20 16:47:55 +08:00
|
|
|
ReactDOM.render(<Test/> , document.getElementById('components-modal-demo-custom'));
|
2015-06-12 17:11:32 +08:00
|
|
|
````
|