2016-06-21 18:50:07 +08:00
|
|
|
---
|
|
|
|
order: 7
|
2016-11-15 15:02:30 +08:00
|
|
|
title:
|
2018-08-25 21:51:19 +08:00
|
|
|
zh-CN: 手动更新和移除
|
|
|
|
en-US: Manual to update destroy
|
2016-06-21 18:50:07 +08:00
|
|
|
---
|
|
|
|
|
2016-08-11 11:41:06 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2018-08-25 21:51:19 +08:00
|
|
|
手动更新和关闭 `Modal.method` 方式创建的对话框。
|
2016-06-21 18:50:07 +08:00
|
|
|
|
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
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2022-05-23 14:37:16 +08:00
|
|
|
import { Button, Modal } from 'antd';
|
2022-05-19 09:46:26 +08:00
|
|
|
import React from 'react';
|
2016-06-21 18:50:07 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const countDown = () => {
|
2018-08-25 21:51:19 +08:00
|
|
|
let secondsToGo = 5;
|
2022-05-19 09:46:26 +08:00
|
|
|
|
2016-06-21 18:50:07 +08:00
|
|
|
const modal = Modal.success({
|
2016-08-11 11:41:06 +08:00
|
|
|
title: 'This is a notification message',
|
2018-08-25 21:51:19 +08:00
|
|
|
content: `This modal will be destroyed after ${secondsToGo} second.`,
|
2016-06-21 18:50:07 +08:00
|
|
|
});
|
2022-05-19 09:46:26 +08:00
|
|
|
|
2018-12-02 20:20:56 +08:00
|
|
|
const timer = setInterval(() => {
|
2018-08-25 21:51:19 +08:00
|
|
|
secondsToGo -= 1;
|
|
|
|
modal.update({
|
|
|
|
content: `This modal will be destroyed after ${secondsToGo} second.`,
|
|
|
|
});
|
|
|
|
}, 1000);
|
2022-05-19 09:46:26 +08:00
|
|
|
|
2018-12-02 20:20:56 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
clearInterval(timer);
|
|
|
|
modal.destroy();
|
|
|
|
}, secondsToGo * 1000);
|
2022-05-19 09:46:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const App: React.FC = () => <Button onClick={countDown}>Open modal to close in 5s</Button>;
|
2016-06-21 18:50:07 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
export default App;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|