2018-08-22 23:34:36 +08:00
---
2018-09-02 15:46:49 +08:00
order: 4
2018-08-22 23:34:36 +08:00
title:
zh-CN: 列表
en-US: List
---
## zh-CN
在列表组件中使用加载占位符。
## en-US
Use skeleton in list component.
2019-05-07 14:57:32 +08:00
```jsx
2019-08-13 14:07:17 +08:00
import { Skeleton, Switch, List, Avatar } from 'antd';
2019-11-28 12:34:33 +08:00
import { StarOutlined, LikeOutlined, MessageOutlined } from '@ant-design/icons';
2018-08-22 23:34:36 +08:00
const listData = [];
for (let i = 0; i < 3 ; i + + ) {
listData.push({
href: 'http://ant.design',
title: `ant design part ${i}` ,
avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',
2019-05-07 14:57:32 +08:00
description:
'Ant Design, a design language for background applications, is refined by Ant UED Team.',
content:
'We supply a series of design principles, practical patterns and high quality design resources (Sketch and Axure), to help people create their product prototypes beautifully and efficiently.',
2018-08-22 23:34:36 +08:00
});
}
2019-08-13 14:07:17 +08:00
const IconText = ({ icon, text }) => (
2018-08-22 23:34:36 +08:00
< span >
2019-08-13 14:07:17 +08:00
{React.createElement(icon, { style: { marginRight: 8 } })}
2018-08-22 23:34:36 +08:00
{text}
< / span >
);
class App extends React.Component {
state = {
loading: true,
2019-05-07 14:57:32 +08:00
};
2018-08-22 23:34:36 +08:00
2019-05-07 14:57:32 +08:00
onChange = checked => {
2018-08-22 23:34:36 +08:00
this.setState({ loading: !checked });
2019-05-07 14:57:32 +08:00
};
2018-08-22 23:34:36 +08:00
render() {
const { loading } = this.state;
return (
< div >
< Switch checked = {!loading} onChange = {this.onChange} / >
< List
itemLayout="vertical"
size="large"
dataSource={listData}
renderItem={item => (
< List.Item
key={item.title}
2019-05-07 14:57:32 +08:00
actions={
!loading & & [
2019-11-28 12:34:33 +08:00
< IconText icon = {StarOutlined} text = "156" key = "list-vertical-star-o" / > ,
< IconText icon = {LikeOutlined} text = "156" key = "list-vertical-like-o" / > ,
< IconText icon = {MessageOutlined} text = "2" key = "list-vertical-message" / > ,
2019-05-07 14:57:32 +08:00
]
}
extra={
!loading & & (
< img
width={272}
alt="logo"
src="https://gw.alipayobjects.com/zos/rmsportal/mqaQswcyDLcXyDKnZfES.png"
/>
)
}
2018-08-22 23:34:36 +08:00
>
2018-09-02 15:46:49 +08:00
< Skeleton loading = {loading} active avatar >
2018-08-22 23:34:36 +08:00
< List.Item.Meta
avatar={< Avatar src = {item.avatar} / > }
title={< a href = {item.href} > {item.title}< / a > }
description={item.description}
/>
{item.content}
< / Skeleton >
< / List.Item >
)}
/>
< / div >
);
}
}
ReactDOM.render(< App / > , mountNode);
2019-05-07 14:57:32 +08:00
```
2018-08-22 23:34:36 +08:00
< style >
.skeleton-demo {
border: 1px solid #f4f4f4 ;
}
< / style >