2018-05-25 20:41:07 +08:00
|
|
|
---
|
2022-05-26 09:53:08 +08:00
|
|
|
order: 4
|
2018-05-25 20:41:07 +08:00
|
|
|
title:
|
|
|
|
zh-CN: Promise 接口
|
|
|
|
en-US: Promise interface
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
可以通过 then 接口在关闭后运行 callback 。以上用例将在每个 message 将要结束时通过 then 显示新的 message 。
|
|
|
|
|
|
|
|
## en-US
|
2019-05-07 14:57:32 +08:00
|
|
|
|
2019-04-19 22:35:06 +08:00
|
|
|
`message` provides a promise interface for `onClose`. The above example will display a new message when the old message is about to close.
|
2018-05-25 20:41:07 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2022-05-21 22:14:15 +08:00
|
|
|
import { Button, message } from 'antd';
|
2022-05-19 09:46:26 +08:00
|
|
|
import React from 'react';
|
2018-05-25 20:41:07 +08:00
|
|
|
|
2022-05-26 09:53:08 +08:00
|
|
|
const App: React.FC = () => {
|
|
|
|
const [messageApi, contextHolder] = message.useMessage();
|
|
|
|
|
|
|
|
const success = () => {
|
|
|
|
messageApi
|
|
|
|
.open({
|
|
|
|
type: 'loading',
|
|
|
|
content: 'Action in progress..',
|
|
|
|
duration: 2.5,
|
|
|
|
})
|
|
|
|
.then(() => message.success('Loading finished', 2.5))
|
|
|
|
.then(() => message.info('Loading finished', 2.5));
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{contextHolder}
|
|
|
|
<Button onClick={success}>Display sequential messages</Button>
|
|
|
|
</>
|
|
|
|
);
|
2018-05-25 20:41:07 +08:00
|
|
|
};
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
export default App;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|