List列表

List 列表

通用列表。

何时使用

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

代码演示

基本用法

基础列表。

<​template>  <​a-list item-layout="horizontal" :data-source="data">    <​template #renderItem="{ item }">      <​a-list-item>        <​a-list-item-meta          description="Ant Design, a design language for background applications, is refined by Ant UED Team"        >          <​template #title>            <​a href="https://www.antdv.com/">{{ item.title }}<​/a>          <​/template>          <​template #avatar>            <​a-avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />          <​/template>        <​/a-list-item-meta>      <​/a-list-item>    <​/template>  <​/a-list><​/template><​script lang="ts">import { defineComponent } from 'vue';interface DataItem {  title: string;}const data: DataItem[] = [  {    title: 'Ant Design Title 1',  },  {    title: 'Ant Design Title 2',  },  {    title: 'Ant Design Title 3',  },  {    title: 'Ant Design Title 4',  },];export default defineComponent({  setup() {    return {      data,    };  },});<​/script>

Small Size

Default Size

Large Size

简单列表

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

<​template>  <​h3 :style="{ margin: '16px 0' }">Small Size<​/h3>  <​a-list size="small" bordered :data-source="data">    <​template #renderItem="{ item }">      <​a-list-item>{{ item }}<​/a-list-item>    <​/template>    <​template #header>      <​div>Header<​/div>    <​/template>    <​template #footer>      <​div>Footer<​/div>    <​/template>  <​/a-list>  <​h3 :style="{ marginBottom: '16px' }">Default Size<​/h3>  <​a-list bordered :data-source="data">    <​template #renderItem="{ item }">      <​a-list-item>{{ item }}<​/a-list-item>    <​/template>    <​template #header>      <​div>Header<​/div>    <​/template>    <​template #footer>      <​div>Footer<​/div>    <​/template>  <​/a-list>  <​h3 :style="{ margin: '16px 0' }">Large Size<​/h3>  <​a-list size="large" bordered :data-source="data">    <​template #renderItem="{ item }">      <​a-list-item>{{ item }}<​/a-list-item>    <​/template>    <​template #header>      <​div>Header<​/div>    <​/template>    <​template #footer>      <​div>Footer<​/div>    <​/template>  <​/a-list><​/template><​script lang="ts">import { defineComponent } from 'vue';const data: string[] = [  'Racing car sprays burning fuel into crowd.',  'Japanese princess to wed commoner.',  'Australian walks 100km after outback crash.',  'Man charged over missing wedding girl.',  'Los Angeles battles huge wildfires.',];export default defineComponent({  setup() {    return {      data,    };  },});<​/script>

加载更多

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

<​template>  <​a-list    class="demo-loadmore-list"    :loading="loading"    item-layout="horizontal"    :data-source="data"  >    <​template #loadMore>      <​div        v-if="showLoadingMore"        :style="{ textAlign: 'center', marginTop: '12px', height: '32px', lineHeight: '32px' }"      >        <​a-spin v-if="loadingMore" />        <​a-button v-else @click="onLoadMore">loading more<​/a-button>      <​/div>    <​/template>    <​template #renderItem="{ item }">      <​a-list-item>        <​template #actions>          <​a>edit<​/a>          <​a>more<​/a>        <​/template>        <​a-list-item-meta          description="Ant Design, a design language for background applications, is refined by Ant UED Team"        >          <​template #title>            <​a href="https://www.antdv.com/">{{ item.name.last }}<​/a>          <​/template>          <​template #avatar>            <​a-avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />          <​/template>        <​/a-list-item-meta>        <​div>content<​/div>      <​/a-list-item>    <​/template>  <​/a-list><​/template><​script lang="ts">import axios, { AxiosResponse } from 'axios';import { defineComponent, ref, onMounted, nextTick } from 'vue';const fakeDataUrl = 'https://randomuser.me/api/?results=5&inc=name,gender,email,nat&noinfo';export default defineComponent({  setup() {    const loading = ref<​boolean>(true);    const loadingMore = ref<​boolean>(false);    const showLoadingMore = ref<​boolean>(true);    const data = ref([]);    onMounted(() => {      getData((res: AxiosResponse) => {        loading.value = false;        data.value = res.data.results;      });    });    const getData = async (callback: (r: AxiosResponse) => void) => {      const res = await axios({        url: fakeDataUrl,        method: 'get',      });      callback(res);    };    const onLoadMore = () => {      loadingMore.value = true;      getData((res: AxiosResponse) => {        data.value = data.value.concat(res.data.results);        loadingMore.value = false;        nextTick(() => {          window.dispatchEvent(new Event('resize'));        });      });    };    return {      loading,      loadingMore,      showLoadingMore,      data,      onLoadMore,    };  },});<​/script><​style scoped>.demo-loadmore-list {  min-height: 350px;}<​/style>

竖排列表样式

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

<​template>  <​a-list item-layout="vertical" size="large" :pagination="pagination" :data-source="listData">    <​template #footer>      <​div>        <​b>ant design vue<​/b>        footer part      <​/div>    <​/template>    <​template #renderItem="{ item }">      <​a-list-item key="item.title">        <​template #actions>          <​span v-for="{ type, text } in actions" :key="type">            <​component v-bind:is="type" style="margin-right: 8px" />            {{ text }}          <​/span>        <​/template>        <​template #extra>          <​img            width="272"            alt="logo"            src="https://gw.alipayobjects.com/zos/rmsportal/mqaQswcyDLcXyDKnZfES.png"          />        <​/template>        <​a-list-item-meta :description="item.description">          <​template #title>            <​a :href="item.href">{{ item.title }}<​/a>          <​/template>          <​template #avatar><​a-avatar :src="item.avatar" /><​/template>        <​/a-list-item-meta>        {{ item.content }}      <​/a-list-item>    <​/template>  <​/a-list><​/template><​script lang="ts">import { StarOutlined, LikeOutlined, MessageOutlined } from '@ant-design/icons-vue';import { defineComponent } from 'vue';const listData: Record<​string, string>[] = [];for (let i = 0; i < 23; i++) {  listData.push({    href: 'https://www.antdv.com/',    title: `ant design vue part ${i}`,    avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',    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.',  });}export default defineComponent({  components: {    StarOutlined,    LikeOutlined,    MessageOutlined,  },  setup() {    const pagination = {      onChange: (page: number) => {        console.log(page);      },      pageSize: 3,    };    const actions: Record<​string, string>[] = [      { type: 'StarOutlined', text: '156' },      { type: 'LikeOutlined', text: '156' },      { type: 'MessageOutlined', text: '2' },    ];    return {      listData,      pagination,      actions,    };  },});<​/script>

栅格列表

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

<​template>  <​a-list :grid="{ gutter: 16, column: 4 }" :data-source="data">    <​template #renderItem="{ item }">      <​a-list-item>        <​a-card :title="item.title">Card content<​/a-card>      <​/a-list-item>    <​/template>  <​/a-list><​/template><​script lang="ts">import { defineComponent } from 'vue';interface DataItem {  title: string;}const data: DataItem[] = [  {    title: 'Title 1',  },  {    title: 'Title 2',  },  {    title: 'Title 3',  },  {    title: 'Title 4',  },];export default defineComponent({  setup() {    return {      data,    };  },});<​/script>

响应式的栅格列表

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