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

39 lines
854 B
Markdown
Raw Normal View History

---
order: 7
title:
zh-CN: 手动更新和移除
en-US: Manual to update destroy
---
2016-08-11 11:41:06 +08:00
## zh-CN
手动更新和关闭 `Modal.method` 方式创建的对话框。
2016-08-11 11:41:06 +08:00
## en-US
2019-04-19 22:06:38 +08:00
Manually updating and destroying a modal from `Modal.method`.
2016-08-11 11:41:06 +08:00
2019-05-07 14:57:32 +08:00
```jsx
import { Modal, Button } from 'antd';
function countDown() {
let secondsToGo = 5;
const modal = Modal.success({
2016-08-11 11:41:06 +08:00
title: 'This is a notification message',
content: `This modal will be destroyed after ${secondsToGo} second.`,
});
const timer = setInterval(() => {
secondsToGo -= 1;
modal.update({
content: `This modal will be destroyed after ${secondsToGo} second.`,
});
}, 1000);
setTimeout(() => {
clearInterval(timer);
modal.destroy();
}, secondsToGo * 1000);
}
2019-05-07 14:57:32 +08:00
ReactDOM.render(<Button onClick={countDown}>Open modal to close in 5s</Button>, mountNode);
```