List列表 - 图1

List 列表

通用列表。

何时使用

最基础的列表展示,可承载文字、列表、图片、段落,常用于后台数据展示页面。

代码演示

List列表 - 图2

基本用法

基础列表。

  1. <template>
  2. <a-list item-layout="horizontal" :data-source="data">
  3. <template #renderItem="{ item }">
  4. <a-list-item>
  5. <a-list-item-meta
  6. description="Ant Design, a design language for background applications, is refined by Ant UED Team"
  7. >
  8. <template #title>
  9. <a href="https://www.antdv.com/">{{ item.title }}</a>
  10. </template>
  11. <template #avatar>
  12. <a-avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />
  13. </template>
  14. </a-list-item-meta>
  15. </a-list-item>
  16. </template>
  17. </a-list>
  18. </template>
  19. <script lang="ts">
  20. import { defineComponent } from 'vue';
  21. interface DataItem {
  22. title: string;
  23. }
  24. const data: DataItem[] = [
  25. {
  26. title: 'Ant Design Title 1',
  27. },
  28. {
  29. title: 'Ant Design Title 2',
  30. },
  31. {
  32. title: 'Ant Design Title 3',
  33. },
  34. {
  35. title: 'Ant Design Title 4',
  36. },
  37. ];
  38. export default defineComponent({
  39. setup() {
  40. return {
  41. data,
  42. };
  43. },
  44. });
  45. </script>

Small Size

List列表 - 图3

Default Size

List列表 - 图4

Large Size

List列表 - 图5

简单列表

列表拥有大、中、小三种尺寸。 通过设置 sizelarge small 分别把按钮设为大、小尺寸。若不设置 size,则尺寸为中。 可通过设置 headerfooter,来自定义列表头部和尾部。

  1. <template>
  2. <h3 :style="{ margin: '16px 0' }">Small Size</h3>
  3. <a-list size="small" bordered :data-source="data">
  4. <template #renderItem="{ item }">
  5. <a-list-item>{{ item }}</a-list-item>
  6. </template>
  7. <template #header>
  8. <div>Header</div>
  9. </template>
  10. <template #footer>
  11. <div>Footer</div>
  12. </template>
  13. </a-list>
  14. <h3 :style="{ marginBottom: '16px' }">Default Size</h3>
  15. <a-list bordered :data-source="data">
  16. <template #renderItem="{ item }">
  17. <a-list-item>{{ item }}</a-list-item>
  18. </template>
  19. <template #header>
  20. <div>Header</div>
  21. </template>
  22. <template #footer>
  23. <div>Footer</div>
  24. </template>
  25. </a-list>
  26. <h3 :style="{ margin: '16px 0' }">Large Size</h3>
  27. <a-list size="large" bordered :data-source="data">
  28. <template #renderItem="{ item }">
  29. <a-list-item>{{ item }}</a-list-item>
  30. </template>
  31. <template #header>
  32. <div>Header</div>
  33. </template>
  34. <template #footer>
  35. <div>Footer</div>
  36. </template>
  37. </a-list>
  38. </template>
  39. <script lang="ts">
  40. import { defineComponent } from 'vue';
  41. const data: string[] = [
  42. 'Racing car sprays burning fuel into crowd.',
  43. 'Japanese princess to wed commoner.',
  44. 'Australian walks 100km after outback crash.',
  45. 'Man charged over missing wedding girl.',
  46. 'Los Angeles battles huge wildfires.',
  47. ];
  48. export default defineComponent({
  49. setup() {
  50. return {
  51. data,
  52. };
  53. },
  54. });
  55. </script>

List列表 - 图6

加载更多

可通过 loadMore 属性实现加载更多功能。

  1. <template>
  2. <a-list
  3. class="demo-loadmore-list"
  4. :loading="loading"
  5. item-layout="horizontal"
  6. :data-source="data"
  7. >
  8. <template #loadMore>
  9. <div
  10. v-if="showLoadingMore"
  11. :style="{ textAlign: 'center', marginTop: '12px', height: '32px', lineHeight: '32px' }"
  12. >
  13. <a-spin v-if="loadingMore" />
  14. <a-button v-else @click="onLoadMore">loading more</a-button>
  15. </div>
  16. </template>
  17. <template #renderItem="{ item }">
  18. <a-list-item>
  19. <template #actions>
  20. <a>edit</a>
  21. <a>more</a>
  22. </template>
  23. <a-list-item-meta
  24. description="Ant Design, a design language for background applications, is refined by Ant UED Team"
  25. >
  26. <template #title>
  27. <a href="https://www.antdv.com/">{{ item.name.last }}</a>
  28. </template>
  29. <template #avatar>
  30. <a-avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />
  31. </template>
  32. </a-list-item-meta>
  33. <div>content</div>
  34. </a-list-item>
  35. </template>
  36. </a-list>
  37. </template>
  38. <script lang="ts">
  39. import axios, { AxiosResponse } from 'axios';
  40. import { defineComponent, ref, onMounted, nextTick } from 'vue';
  41. const fakeDataUrl = 'https://randomuser.me/api/?results=5&inc=name,gender,email,nat&noinfo';
  42. export default defineComponent({
  43. setup() {
  44. const loading = ref<boolean>(true);
  45. const loadingMore = ref<boolean>(false);
  46. const showLoadingMore = ref<boolean>(true);
  47. const data = ref([]);
  48. onMounted(() => {
  49. getData((res: AxiosResponse) => {
  50. loading.value = false;
  51. data.value = res.data.results;
  52. });
  53. });
  54. const getData = async (callback: (r: AxiosResponse) => void) => {
  55. const res = await axios({
  56. url: fakeDataUrl,
  57. method: 'get',
  58. });
  59. callback(res);
  60. };
  61. const onLoadMore = () => {
  62. loadingMore.value = true;
  63. getData((res: AxiosResponse) => {
  64. data.value = data.value.concat(res.data.results);
  65. loadingMore.value = false;
  66. nextTick(() => {
  67. window.dispatchEvent(new Event('resize'));
  68. });
  69. });
  70. };
  71. return {
  72. loading,
  73. loadingMore,
  74. showLoadingMore,
  75. data,
  76. onLoadMore,
  77. };
  78. },
  79. });
  80. </script>
  81. <style scoped>
  82. .demo-loadmore-list {
  83. min-height: 350px;
  84. }
  85. </style>

List列表 - 图7

竖排列表样式

通过设置 itemLayout 属性为 vertical 可实现竖排列表样式。

  1. <template>
  2. <a-list item-layout="vertical" size="large" :pagination="pagination" :data-source="listData">
  3. <template #footer>
  4. <div>
  5. <b>ant design vue</b>
  6. footer part
  7. </div>
  8. </template>
  9. <template #renderItem="{ item }">
  10. <a-list-item key="item.title">
  11. <template #actions>
  12. <span v-for="{ type, text } in actions" :key="type">
  13. <component v-bind:is="type" style="margin-right: 8px" />
  14. {{ text }}
  15. </span>
  16. </template>
  17. <template #extra>
  18. <img
  19. width="272"
  20. alt="logo"
  21. src="https://gw.alipayobjects.com/zos/rmsportal/mqaQswcyDLcXyDKnZfES.png"
  22. />
  23. </template>
  24. <a-list-item-meta :description="item.description">
  25. <template #title>
  26. <a :href="item.href">{{ item.title }}</a>
  27. </template>
  28. <template #avatar><a-avatar :src="item.avatar" /></template>
  29. </a-list-item-meta>
  30. {{ item.content }}
  31. </a-list-item>
  32. </template>
  33. </a-list>
  34. </template>
  35. <script lang="ts">
  36. import { StarOutlined, LikeOutlined, MessageOutlined } from '@ant-design/icons-vue';
  37. import { defineComponent } from 'vue';
  38. const listData: Record<string, string>[] = [];
  39. for (let i = 0; i < 23; i++) {
  40. listData.push({
  41. href: 'https://www.antdv.com/',
  42. title: `ant design vue part ${i}`,
  43. avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',
  44. description:
  45. 'Ant Design, a design language for background applications, is refined by Ant UED Team.',
  46. content:
  47. '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.',
  48. });
  49. }
  50. export default defineComponent({
  51. components: {
  52. StarOutlined,
  53. LikeOutlined,
  54. MessageOutlined,
  55. },
  56. setup() {
  57. const pagination = {
  58. onChange: (page: number) => {
  59. console.log(page);
  60. },
  61. pageSize: 3,
  62. };
  63. const actions: Record<string, string>[] = [
  64. { type: 'StarOutlined', text: '156' },
  65. { type: 'LikeOutlined', text: '156' },
  66. { type: 'MessageOutlined', text: '2' },
  67. ];
  68. return {
  69. listData,
  70. pagination,
  71. actions,
  72. };
  73. },
  74. });
  75. </script>

List列表 - 图8

栅格列表

可以通过设置 Listgrid 属性来实现栅格列表,column 可设置期望显示的列数。

  1. <template>
  2. <a-list :grid="{ gutter: 16, column: 4 }" :data-source="data">
  3. <template #renderItem="{ item }">
  4. <a-list-item>
  5. <a-card :title="item.title">Card content</a-card>
  6. </a-list-item>
  7. </template>
  8. </a-list>
  9. </template>
  10. <script lang="ts">
  11. import { defineComponent } from 'vue';
  12. interface DataItem {
  13. title: string;
  14. }
  15. const data: DataItem[] = [
  16. {
  17. title: 'Title 1',
  18. },
  19. {
  20. title: 'Title 2',
  21. },
  22. {
  23. title: 'Title 3',
  24. },
  25. {
  26. title: 'Title 4',
  27. },
  28. ];
  29. export default defineComponent({
  30. setup() {
  31. return {
  32. data,
  33. };
  34. },
  35. });
  36. </script>

List列表 - 图9

响应式的栅格列表

响应式的栅格列表。尺寸与 Layout Grid 保持一致。

  1. <template>
  2. <a-list :grid="{ gutter: 16, xs: 1, sm: 2, md: 4, lg: 4, xl: 6, xxl: 3 }" :data-source="data">
  3. <template #renderItem="{ item }">
  4. <a-list-item>
  5. <a-card :title="item.title">Card content</a-card>
  6. </a-list-item>
  7. </template>
  8. </a-list>
  9. </template>
  10. <script lang="ts">
  11. import { defineComponent } from 'vue';
  12. interface DataItem {
  13. title: string;
  14. }
  15. const data: DataItem[] = [
  16. {
  17. title: 'Title 1',
  18. },
  19. {
  20. title: 'Title 2',
  21. },
  22. {
  23. title: 'Title 3',
  24. },
  25. {
  26. title: 'Title 4',
  27. },
  28. {
  29. title: 'Title 5',
  30. },
  31. {
  32. title: 'Title 6',
  33. },
  34. ];
  35. export default defineComponent({
  36. setup() {
  37. return {
  38. data,
  39. };
  40. },
  41. });
  42. </script>

API

List

参数说明类型默认值版本
bordered是否展示边框booleanfalse
footer列表底部string|slot-
grid列表栅格配置object-
header列表头部string|slot-
itemLayout设置 List.Item 布局, 设置成 vertical 则竖直样式显示, 默认横排string-
loading当卡片内容还在加载中时,可以用 loading 展示一个占位boolean|objectfalse
loadMore加载更多string|slot-
locale默认文案设置,目前包括空数据文案objectemptyText: ‘暂无数据’
pagination对应的 pagination 配置, 设置 false 不显示boolean|objectfalse
sizelist 的尺寸default | middle | smalldefault
split是否展示分割线booleantrue
dataSource列表数据源any[]-1.5.0
renderItem自定义Item函数,也可使用 #renderItem=”{item, index}”({item, index}) => vNode-
rowKey各项 key 的取值,可以是字符串或一个函数item => string|number

pagination

分页的配置项。

参数说明类型默认值
position指定分页显示的位置‘top’ | ‘bottom’ | ‘both’‘bottom’

更多配置项,请查看 Pagination

List grid props

参数说明类型默认值
column列数number oneOf [ 1, 2, 3, 4, 6, 8, 12, 24]-
gutter栅格间隔number0
xs<576px 展示的列数number-
sm≥576px 展示的列数number-
md≥768px 展示的列数number-
lg≥992px 展示的列数number-
xl≥1200px 展示的列数number-
xxl≥1600px 展示的列数number-

List.Item

参数说明类型默认值
actions列表操作组,根据 itemLayout 的不同, 位置在卡片底部或者最右侧Array<vNode>/slot
extra额外内容, 通常用在 itemLayoutvertical 的情况下, 展示右侧内容; horizontal 展示在列表元素最右侧string|slot-

List.Item.Meta

参数说明类型默认值
avatar列表元素的图标slot-
description列表元素的描述内容string|slot-
title列表元素的标题string|slot-