2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 4
|
2016-04-22 14:52:19 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 加载中状态
|
|
|
|
en-US: Loading
|
2016-03-31 09:40:55 +08:00
|
|
|
---
|
2015-06-17 21:29:58 +08:00
|
|
|
|
2016-04-22 14:52:19 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2015-12-28 13:57:02 +08:00
|
|
|
添加 `loading` 属性即可让按钮处于加载状态,最后两个按钮演示点击后进入加载状态。
|
2015-06-05 20:26:41 +08:00
|
|
|
|
2016-04-22 14:52:19 +08:00
|
|
|
## en-US
|
|
|
|
|
2016-04-25 11:04:56 +08:00
|
|
|
A loading indicator can be added to a button by setting the `loading` property on the `Button`.
|
2016-04-22 14:52:19 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2016-04-12 12:17:03 +08:00
|
|
|
import { Button } from 'antd';
|
2019-12-19 11:51:12 +08:00
|
|
|
import { PoweroffOutlined } from '@ant-design/icons';
|
2015-09-27 16:30:35 +08:00
|
|
|
|
2017-02-19 20:53:31 +08:00
|
|
|
class App extends React.Component {
|
|
|
|
state = {
|
2020-04-26 16:21:07 +08:00
|
|
|
loadings: [],
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2017-02-19 20:53:31 +08:00
|
|
|
|
2020-04-26 16:21:07 +08:00
|
|
|
enterLoading = index => {
|
2020-06-02 12:54:22 +08:00
|
|
|
this.setState(({ loadings }) => {
|
|
|
|
const newLoadings = [...loadings];
|
|
|
|
newLoadings[index] = true;
|
|
|
|
|
|
|
|
return {
|
|
|
|
loadings: newLoadings,
|
|
|
|
};
|
2020-04-26 16:21:07 +08:00
|
|
|
});
|
2020-04-10 15:39:07 +08:00
|
|
|
setTimeout(() => {
|
2020-06-02 12:54:22 +08:00
|
|
|
this.setState(({ loadings }) => {
|
|
|
|
const newLoadings = [...loadings];
|
|
|
|
newLoadings[index] = false;
|
|
|
|
|
|
|
|
return {
|
|
|
|
loadings: newLoadings,
|
|
|
|
};
|
|
|
|
});
|
2020-04-26 16:21:07 +08:00
|
|
|
}, 6000);
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2017-02-19 20:53:31 +08:00
|
|
|
|
2015-07-29 22:23:55 +08:00
|
|
|
render() {
|
2020-04-26 16:21:07 +08:00
|
|
|
const { loadings } = this.state;
|
2016-01-07 16:29:12 +08:00
|
|
|
return (
|
2020-04-26 16:21:07 +08:00
|
|
|
<>
|
2016-01-07 16:29:12 +08:00
|
|
|
<Button type="primary" loading>
|
2016-04-22 14:52:19 +08:00
|
|
|
Loading
|
2016-01-07 16:29:12 +08:00
|
|
|
</Button>
|
|
|
|
<Button type="primary" size="small" loading>
|
2016-04-22 14:52:19 +08:00
|
|
|
Loading
|
2016-04-15 16:21:08 +08:00
|
|
|
</Button>
|
2020-04-26 16:21:07 +08:00
|
|
|
<Button type="primary" icon={<PoweroffOutlined />} loading />
|
2016-01-07 16:29:12 +08:00
|
|
|
<br />
|
2020-04-26 16:21:07 +08:00
|
|
|
<Button type="primary" loading={loadings[0]} onClick={() => this.enterLoading(0)}>
|
2016-04-22 14:52:19 +08:00
|
|
|
Click me!
|
2016-01-07 16:29:12 +08:00
|
|
|
</Button>
|
2019-05-07 14:57:32 +08:00
|
|
|
<Button
|
|
|
|
type="primary"
|
2019-12-19 11:51:12 +08:00
|
|
|
icon={<PoweroffOutlined />}
|
2020-04-26 16:21:07 +08:00
|
|
|
loading={loadings[1]}
|
|
|
|
onClick={() => this.enterLoading(1)}
|
2019-05-07 14:57:32 +08:00
|
|
|
>
|
2016-04-22 14:52:19 +08:00
|
|
|
Click me!
|
2016-01-07 16:29:12 +08:00
|
|
|
</Button>
|
2020-04-26 16:21:07 +08:00
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
icon={<PoweroffOutlined />}
|
|
|
|
loading={loadings[2]}
|
|
|
|
onClick={() => this.enterLoading(2)}
|
|
|
|
/>
|
|
|
|
</>
|
2016-01-07 16:29:12 +08:00
|
|
|
);
|
2017-02-19 20:53:31 +08:00
|
|
|
}
|
|
|
|
}
|
2015-07-29 22:23:55 +08:00
|
|
|
|
2015-12-29 12:08:58 +08:00
|
|
|
ReactDOM.render(<App />, mountNode);
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|