• 列表
    • 何时使用
    • 代码演示
      • 基础列表
      • 栅格列表
      • 加载更多
      • 响应式的栅格列表
      • 简单列表
      • 竖排列表样式
      • 滚动加载
      • 滚动加载无限长列表
  • API
    • List
    • pagination
    • List grid props
    • List.Item
    • List.Item.Meta

    列表

    通用列表。

    何时使用

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

    代码演示

    List 列表 - 图1

    基础列表

    基础列表。

    1. <template>
    2. <a-list itemLayout="horizontal" :dataSource="data">
    3. <a-list-item slot="renderItem" slot-scope="item, index">
    4. <a-list-item-meta
    5. description="Ant Design, a design language for background applications, is refined by Ant UED Team"
    6. >
    7. <a slot="title" href="https://www.antdv.com/">{{item.title}}</a>
    8. <a-avatar
    9. slot="avatar"
    10. src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
    11. />
    12. </a-list-item-meta>
    13. </a-list-item>
    14. </a-list>
    15. </template>
    16. <script>
    17. const data = [
    18. {
    19. title: 'Ant Design Title 1',
    20. },
    21. {
    22. title: 'Ant Design Title 2',
    23. },
    24. {
    25. title: 'Ant Design Title 3',
    26. },
    27. {
    28. title: 'Ant Design Title 4',
    29. },
    30. ];
    31. export default {
    32. data() {
    33. return {
    34. data,
    35. };
    36. },
    37. };
    38. </script>
    39. <style></style>

    List 列表 - 图2

    栅格列表

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

    1. <template>
    2. <a-list :grid="{ gutter: 16, column: 4 }" :dataSource="data">
    3. <a-list-item slot="renderItem" slot-scope="item, index">
    4. <a-card :title="item.title">Card content</a-card>
    5. </a-list-item>
    6. </a-list>
    7. </template>
    8. <script>
    9. const data = [
    10. {
    11. title: 'Title 1',
    12. },
    13. {
    14. title: 'Title 2',
    15. },
    16. {
    17. title: 'Title 3',
    18. },
    19. {
    20. title: 'Title 4',
    21. },
    22. ];
    23. export default {
    24. data() {
    25. return {
    26. data,
    27. };
    28. },
    29. };
    30. </script>
    31. <style></style>

    List 列表 - 图3

    加载更多

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

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

    List 列表 - 图4

    响应式的栅格列表

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

    1. <template>
    2. <a-list :grid="{ gutter: 16, xs: 1, sm: 2, md: 4, lg: 4, xl: 6, xxl: 3 }" :dataSource="data">
    3. <a-list-item slot="renderItem" slot-scope="item, index">
    4. <a-card :title="item.title">Card content</a-card>
    5. </a-list-item>
    6. </a-list>
    7. </template>
    8. <script>
    9. const data = [
    10. {
    11. title: 'Title 1',
    12. },
    13. {
    14. title: 'Title 2',
    15. },
    16. {
    17. title: 'Title 3',
    18. },
    19. {
    20. title: 'Title 4',
    21. },
    22. {
    23. title: 'Title 5',
    24. },
    25. {
    26. title: 'Title 6',
    27. },
    28. ];
    29. export default {
    30. data() {
    31. return {
    32. data,
    33. };
    34. },
    35. };
    36. </script>
    37. <style></style>

    List 列表 - 图5

    简单列表

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

    1. <template>
    2. <div>
    3. <h3 :style="{ marginBottom: '16px' }">Default Size</h3>
    4. <a-list bordered :dataSource="data">
    5. <a-list-item slot="renderItem" slot-scope="item, index">{{item}}</a-list-item>
    6. <div slot="header">Header</div>
    7. <div slot="footer">Footer</div>
    8. </a-list>
    9. <h3 :style="{ margin: '16px 0' }">Small Size</h3>
    10. <a-list size="small" bordered :dataSource="data">
    11. <a-list-item slot="renderItem" slot-scope="item, index">{{item}}</a-list-item>
    12. <div slot="header">Header</div>
    13. <div slot="footer">Footer</div>
    14. </a-list>
    15. <h3 :style="{ margin: '16px 0' }">Large Size</h3>
    16. <a-list size="large" bordered :dataSource="data">
    17. <a-list-item slot="renderItem" slot-scope="item, index">{{item}}</a-list-item>
    18. <div slot="header">Header</div>
    19. <div slot="footer">Footer</div>
    20. </a-list>
    21. </div>
    22. </template>
    23. <script>
    24. const data = [
    25. 'Racing car sprays burning fuel into crowd.',
    26. 'Japanese princess to wed commoner.',
    27. 'Australian walks 100km after outback crash.',
    28. 'Man charged over missing wedding girl.',
    29. 'Los Angeles battles huge wildfires.',
    30. ];
    31. export default {
    32. data() {
    33. return {
    34. data,
    35. };
    36. },
    37. };
    38. </script>
    39. <style></style>

    List 列表 - 图6

    竖排列表样式

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

    1. <template>
    2. <a-list itemLayout="vertical" size="large" :pagination="pagination" :dataSource="listData">
    3. <div slot="footer"><b>ant design vue</b> footer part</div>
    4. <a-list-item slot="renderItem" slot-scope="item, index" key="item.title">
    5. <template slot="actions" v-for="{type, text} in actions">
    6. <span :key="type">
    7. <a-icon :type="type" style="margin-right: 8px" />
    8. {{text}}
    9. </span>
    10. </template>
    11. <img
    12. slot="extra"
    13. width="272"
    14. alt="logo"
    15. src="https://gw.alipayobjects.com/zos/rmsportal/mqaQswcyDLcXyDKnZfES.png"
    16. />
    17. <a-list-item-meta :description="item.description">
    18. <a slot="title" :href="item.href">{{item.title}}</a>
    19. <a-avatar slot="avatar" :src="item.avatar" />
    20. </a-list-item-meta>
    21. {{item.content}}
    22. </a-list-item>
    23. </a-list>
    24. </template>
    25. <script>
    26. const listData = [];
    27. for (let i = 0; i < 23; i++) {
    28. listData.push({
    29. href: 'https://www.antdv.com/',
    30. title: `ant design vue part ${i}`,
    31. avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',
    32. description:
    33. 'Ant Design, a design language for background applications, is refined by Ant UED Team.',
    34. content:
    35. '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.',
    36. });
    37. }
    38. export default {
    39. data() {
    40. return {
    41. listData,
    42. pagination: {
    43. onChange: page => {
    44. console.log(page);
    45. },
    46. pageSize: 3,
    47. },
    48. actions: [
    49. { type: 'star-o', text: '156' },
    50. { type: 'like-o', text: '156' },
    51. { type: 'message', text: '2' },
    52. ],
    53. };
    54. },
    55. };
    56. </script>
    57. <style></style>

    List 列表 - 图7

    滚动加载

    结合 vue-infinite-scroll 实现滚动自动加载列表。

    1. <template>
    2. <div
    3. class="demo-infinite-container"
    4. v-infinite-scroll="handleInfiniteOnLoad"
    5. :infinite-scroll-disabled="busy"
    6. :infinite-scroll-distance="10"
    7. >
    8. <a-list :dataSource="data">
    9. <a-list-item slot="renderItem" slot-scope="item, index">
    10. <a-list-item-meta :description="item.email">
    11. <a slot="title" :href="item.href">{{item.name.last}}</a>
    12. <a-avatar
    13. slot="avatar"
    14. src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
    15. />
    16. </a-list-item-meta>
    17. <div>Content</div>
    18. </a-list-item>
    19. <div v-if="loading && !busy" class="demo-loading-container">
    20. <a-spin />
    21. </div>
    22. </a-list>
    23. </div>
    24. </template>
    25. <script>
    26. import reqwest from 'reqwest';
    27. import infiniteScroll from 'vue-infinite-scroll';
    28. const fakeDataUrl = 'https://randomuser.me/api/?results=5&inc=name,gender,email,nat&noinfo';
    29. export default {
    30. directives: { infiniteScroll },
    31. data() {
    32. return {
    33. data: [],
    34. loading: false,
    35. busy: false,
    36. };
    37. },
    38. beforeMount() {
    39. this.fetchData(res => {
    40. this.data = res.results;
    41. });
    42. },
    43. methods: {
    44. fetchData(callback) {
    45. reqwest({
    46. url: fakeDataUrl,
    47. type: 'json',
    48. method: 'get',
    49. contentType: 'application/json',
    50. success: res => {
    51. callback(res);
    52. },
    53. });
    54. },
    55. handleInfiniteOnLoad() {
    56. const data = this.data;
    57. this.loading = true;
    58. if (data.length > 14) {
    59. this.$message.warning('Infinite List loaded all');
    60. this.busy = true;
    61. this.loading = false;
    62. return;
    63. }
    64. this.fetchData(res => {
    65. this.data = data.concat(res.results);
    66. this.loading = false;
    67. });
    68. },
    69. },
    70. };
    71. </script>
    72. <style>
    73. .demo-infinite-container {
    74. border: 1px solid #e8e8e8;
    75. border-radius: 4px;
    76. overflow: auto;
    77. padding: 8px 24px;
    78. height: 300px;
    79. }
    80. .demo-loading-container {
    81. position: absolute;
    82. bottom: 40px;
    83. width: 100%;
    84. text-align: center;
    85. }
    86. </style>

    List 列表 - 图8

    滚动加载无限长列表

    结合 vue-virtual-scroller 实现滚动加载无限长列表,带有虚拟化(virtualization)功能,能够提高数据量大时候长列表的性能。可以结合 vue-infinite-scroll 实现滚动自动加载无限长列表。 virtualized 是在大数据列表中应用的一种技术,主要是为了减少不可见区域不必要的渲染从而提高性能,特别是数据量在成千上万条效果尤为明显。

    1. <template>
    2. <a-list>
    3. <virtual-scroller
    4. style="height: 400px"
    5. :items="data"
    6. item-height="73"
    7. v-infinite-scroll="handleInfiniteOnLoad"
    8. :infinite-scroll-disabled="busy"
    9. :infinite-scroll-distance="10"
    10. >
    11. <a-list-item slot-scope="{item}">
    12. <a-list-item-meta :description="item.email">
    13. <a slot="title" :href="item.href">{{item.name.last}}</a>
    14. <a-avatar
    15. slot="avatar"
    16. src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
    17. />
    18. </a-list-item-meta>
    19. <div>Content {{item.index}}</div>
    20. </a-list-item>
    21. </virtual-scroller>
    22. <a-spin v-if="loading" class="demo-loading" />
    23. </a-list>
    24. </template>
    25. <script>
    26. import reqwest from 'reqwest';
    27. import infiniteScroll from 'vue-infinite-scroll';
    28. import { VirtualScroller } from 'vue-virtual-scroller';
    29. const fakeDataUrl = 'https://randomuser.me/api/?results=10&inc=name,gender,email,nat&noinfo';
    30. export default {
    31. directives: { infiniteScroll },
    32. data() {
    33. return {
    34. data: [],
    35. loading: false,
    36. busy: false,
    37. };
    38. },
    39. beforeMount() {
    40. this.fetchData(res => {
    41. this.data = res.results.map((item, index) => ({ ...item, index }));
    42. });
    43. },
    44. methods: {
    45. fetchData(callback) {
    46. reqwest({
    47. url: fakeDataUrl,
    48. type: 'json',
    49. method: 'get',
    50. contentType: 'application/json',
    51. success: res => {
    52. callback(res);
    53. },
    54. });
    55. },
    56. handleInfiniteOnLoad() {
    57. const data = this.data;
    58. this.loading = true;
    59. if (data.length > 100) {
    60. this.$message.warning('Infinite List loaded all');
    61. this.busy = true;
    62. this.loading = false;
    63. return;
    64. }
    65. this.fetchData(res => {
    66. this.data = data.concat(res.results).map((item, index) => ({ ...item, index }));
    67. this.loading = false;
    68. });
    69. },
    70. },
    71. components: {
    72. 'virtual-scroller': VirtualScroller,
    73. },
    74. };
    75. </script>
    76. <style>
    77. .demo-loading {
    78. position: absolute;
    79. bottom: 40px;
    80. width: 100%;
    81. text-align: center;
    82. }
    83. </style>

    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
    renderItem自定义Item函数,也可使用 slot="renderItem" 和 slot-scope="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-