2016-03-31 09:40:55 +08:00
---
order: 2
2016-08-23 21:00:35 +08:00
title:
2016-08-11 11:41:06 +08:00
zh-CN: 自定义页脚
2017-02-19 01:42:58 +08:00
en-US: Customized Footer
2016-03-31 09:40:55 +08:00
---
2015-06-12 17:37:39 +08:00
2016-08-11 11:41:06 +08:00
## zh-CN
2015-06-12 17:44:29 +08:00
更复杂的例子,自定义了页脚的按钮,点击提交后进入 loading 状态,完成后关闭。
2015-06-12 17:37:39 +08:00
2017-02-19 01:42:58 +08:00
不需要默认确定取消按钮时,你可以把 `footer` 设为 `null` 。
2016-08-11 11:41:06 +08:00
## en-US
2019-05-07 14:57:32 +08:00
A more complex example which define a customized footer button bar. The dialog will change to loading state after clicking the submit button, and when the loading is done, the modal dialog will be closed.
2016-08-11 11:41:06 +08:00
2017-02-19 01:42:58 +08:00
You could set `footer` to `null` if you don't need default footer buttons.
2019-05-07 14:57:32 +08:00
```jsx
2015-10-28 20:55:49 +08:00
import { Modal, Button } from 'antd';
2015-06-12 17:37:39 +08:00
2017-02-20 22:02:12 +08:00
class App extends React.Component {
state = {
loading: false,
visible: false,
2019-05-07 14:57:32 +08:00
};
2018-06-27 15:55:04 +08:00
2017-02-20 22:02:12 +08:00
showModal = () => {
2015-08-18 11:46:07 +08:00
this.setState({
2016-05-11 09:32:33 +08:00
visible: true,
2015-08-18 11:46:07 +08:00
});
2019-05-07 14:57:32 +08:00
};
2018-06-27 15:55:04 +08:00
2017-02-20 22:02:12 +08:00
handleOk = () => {
2015-06-12 17:44:29 +08:00
this.setState({ loading: true });
2015-08-18 11:46:07 +08:00
setTimeout(() => {
2015-06-15 21:30:17 +08:00
this.setState({ loading: false, visible: false });
2015-06-12 17:37:39 +08:00
}, 3000);
2019-05-07 14:57:32 +08:00
};
2018-06-27 15:55:04 +08:00
2017-02-20 22:02:12 +08:00
handleCancel = () => {
2015-06-15 21:30:17 +08:00
this.setState({ visible: false });
2019-05-07 14:57:32 +08:00
};
2018-06-27 15:55:04 +08:00
2015-06-12 17:37:39 +08:00
render() {
2017-05-16 10:43:12 +08:00
const { visible, loading } = this.state;
2016-01-07 16:29:12 +08:00
return (
< div >
< Button type = "primary" onClick = {this.showModal} >
2018-08-25 22:04:15 +08:00
Open Modal with customized footer
2016-01-07 16:29:12 +08:00
< / Button >
2016-08-23 21:00:35 +08:00
< Modal
2017-05-16 10:43:12 +08:00
visible={visible}
2016-08-23 21:00:35 +08:00
title="Title"
onOk={this.handleOk}
onCancel={this.handleCancel}
2016-01-08 14:41:05 +08:00
footer={[
2019-05-07 14:57:32 +08:00
< Button key = "back" onClick = {this.handleCancel} >
Return
< / Button > ,
2017-09-27 22:32:49 +08:00
< Button key = "submit" type = "primary" loading = {loading} onClick = {this.handleOk} >
2016-08-11 11:41:06 +08:00
Submit
2016-05-11 09:32:33 +08:00
< / Button > ,
2016-06-06 13:54:10 +08:00
]}
>
2016-08-11 11:41:06 +08:00
< p > Some contents...< / p >
< p > Some contents...< / p >
< p > Some contents...< / p >
< p > Some contents...< / p >
< p > Some contents...< / p >
2016-01-07 16:29:12 +08:00
< / Modal >
< / div >
);
2017-02-20 22:02:12 +08:00
}
}
2015-06-12 17:37:39 +08:00
2017-02-20 22:02:12 +08:00
ReactDOM.render(< App / > , mountNode);
2019-05-07 14:57:32 +08:00
```