ant-design/components/spin/demo/delayAndDebounce.md

50 lines
1013 B
Markdown
Raw Normal View History

---
order: 5
title:
zh-CN: 延迟
en-US: delay
---
## zh-CN
延迟显示 loading 效果。当 spinning 状态在 `delay` 时间内结束,则不显示 loading 状态。
## en-US
Specifies a delay for loading state. If `spinning` ends during delay, loading status won't appear.
2019-05-07 14:57:32 +08:00
```jsx
import { Spin, Alert, Switch } from 'antd';
class Card extends React.Component {
2019-05-07 14:57:32 +08:00
state = { loading: false };
2018-06-27 15:55:04 +08:00
2019-05-07 14:57:32 +08:00
toggle = value => {
this.setState({ loading: value });
2019-05-07 14:57:32 +08:00
};
2018-06-27 15:55:04 +08:00
render() {
const container = (
2017-01-07 22:07:09 +08:00
<Alert
message="Alert message title"
description="Further details about the context of this alert."
type="info"
/>
);
return (
<div>
2019-05-07 14:57:32 +08:00
<Spin spinning={this.state.loading} delay={500}>
{container}
</Spin>
<div style={{ marginTop: 16 }}>
2019-05-07 14:57:32 +08:00
Loading state
<Switch checked={this.state.loading} onChange={this.toggle} />
</div>
</div>
);
}
}
ReactDOM.render(<Card />, mountNode);
2019-05-07 14:57:32 +08:00
```