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.
2022-05-19 09:46:26 +08:00
```tsx
import type Icon from '@ant-design/icons';
2022-05-26 23:33:46 +08:00
import { LikeOutlined, MessageOutlined, StarOutlined } from '@ant-design/icons';
import { Avatar, List, Skeleton, Switch } from 'antd';
import React, { useState } from 'react';
2018-08-22 23:34:36 +08:00
2022-05-19 09:46:26 +08:00
interface IconTextProps {
icon: typeof Icon;
text: React.ReactNode;
2018-08-22 23:34:36 +08:00
}
2022-05-19 09:46:26 +08:00
const listData = Array.from({ length: 3 }).map((_, i) => ({
href: 'https://ant.design',
title: `ant design part ${i}` ,
avatar: 'https://joeschmoe.io/api/v1/random',
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.',
}));
const IconText = ({ icon, text }: IconTextProps) => (
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 >
);
2022-05-19 09:46:26 +08:00
const App: React.FC = () => {
const [loading, setLoading] = useState(true);
2018-08-22 23:34:36 +08:00
2022-05-19 09:46:26 +08:00
const onChange = (checked: boolean) => {
2022-05-26 23:33:46 +08:00
setLoading(!checked);
2019-05-07 14:57:32 +08:00
};
2022-05-19 09:46:26 +08:00
return (
< >
< Switch checked = {!loading} onChange = {onChange} / >
2018-08-22 23:34:36 +08:00
2022-05-19 09:46:26 +08:00
< List
itemLayout="vertical"
size="large"
dataSource={listData}
renderItem={item => (
< List.Item
key={item.title}
actions={
!loading
? [
< 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" / > ,
]
: undefined
}
extra={
!loading & & (
< img
width={272}
alt="logo"
src="https://gw.alipayobjects.com/zos/rmsportal/mqaQswcyDLcXyDKnZfES.png"
2018-08-22 23:34:36 +08:00
/>
2022-05-19 09:46:26 +08:00
)
}
>
< Skeleton loading = {loading} active avatar >
< List.Item.Meta
avatar={< Avatar src = {item.avatar} / > }
title={< a href = {item.href} > {item.title}< / a > }
description={item.description}
/>
{item.content}
< / Skeleton >
< / List.Item >
)}
/>
< />
);
};
2018-08-22 23:34:36 +08:00
2022-04-15 16:20:56 +08:00
export default App;
2019-05-07 14:57:32 +08:00
```
2018-08-22 23:34:36 +08:00
< style >
.skeleton-demo {
border: 1px solid #f4f4f4 ;
}
< / style >