ant-design/components/modal/demo/custom.md

57 lines
1.1 KiB
Markdown
Raw Normal View History

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;
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
};
},
showModal() {
2015-06-12 23:31:44 +08:00
this.setState({
2015-06-14 13:20:35 +08:00
visible: true
2015-06-12 23:31:44 +08:00
});
2015-06-12 17:11:32 +08:00
},
handleOk() {
this.setState({
ModalText: '对话框将在两秒后关闭'
});
setTimeout((function() {
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-06-12 17:11:32 +08:00
}).bind(this), 2000);
},
handleCancel() {
console.log('点击了取消');
2015-06-25 15:35:46 +08:00
this.setState({
visible: false
});
2015-06-12 17:11:32 +08:00
},
render() {
return <div>
<button className="ant-btn ant-btn-primary" onClick={this.showModal}>显示对话框</button>
<Modal ref="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>;
}
});
React.render(<Test/> , document.getElementById('components-modal-demo-custom'));
````