Card卡片
Card 卡片
通用卡片容器
何时使用
最基础的卡片容器,可承载文字、列表、图片、段落,常用于后台概览页面。
代码演示
典型卡片
包含标题、内容、操作区域。 可通过设置size为default或者small,控制尺寸
<template> <a-card title="Default size card" style="width: 300px"> <template #extra><a href="#">more</a></template> <p>card content</p> <p>card content</p> <p>card content</p> </a-card> <br /> <a-card size="small" title="Small size card" style="width: 300px"> <template #extra><a href="#">more</a></template> <p>card content</p> <p>card content</p> <p>card content</p> </a-card></template>
更灵活的内容展示
可以利用 Card.Meta 支持更灵活的内容
<template> <a-card hoverable style="width: 240px"> <template #cover> <img alt="example" src="https://os.alipayobjects.com/rmsportal/QBnOOoLaAfKPirc.png" /> </template> <a-card-meta title="Europe Street beat"> <template #description>www.instagram.com</template> </a-card-meta> </a-card></template>
栅格卡片
在系统概览页面常常和栅格进行配合。
<template> <div style="background-color: #ececec; padding: 20px"> <a-row :gutter="16"> <a-col :span="8"> <a-card title="Card title" :bordered="false"> <p>card content</p> </a-card> </a-col> <a-col :span="8"> <a-card title="Card title" :bordered="false"> <p>card content</p> </a-card> </a-col> <a-col :span="8"> <a-card title="Card title" :bordered="false"> <p>card content</p> </a-card> </a-col> </a-row> </div></template>
Toggle loading
预加载的卡片
数据读入前会有文本块样式
<template> <a-card :loading="loading" title="Card title">whatever content</a-card> <a-button style="margin-top: 16px" @click="handleClick">Toggle loading</a-button></template><script lang="ts">import { defineComponent, ref } from 'vue';export default defineComponent({ setup() { const loading = ref(true); const handleClick = () => { loading.value = !loading.value; }; return { loading, handleClick, }; },});</script>
简洁卡片
只包含内容区域。
<template> <a-card style="width: 300px"> <p>Card content</p> <p>Card content</p> <p>Card content</p> </a-card></template>
无边框
在灰色背景上使用无边框的卡片
<template> <div style="background: #ececec; padding: 30px"> <a-card title="Card title" :bordered="false" style="width: 300px"> <p>Card content</p> <p>Card content</p> <p>Card content</p> </a-card> </div></template>
网格型内嵌卡片
一种常见的卡片内容区隔模式。
<template> <a-card title="Card Title"> <a-card-grid style="width: 25%; text-align: center">Content</a-card-grid> <a-card-grid style="width: 25%; text-align: center" :hoverable="false">Content</a-card-grid> <a-card-grid style="width: 25%; text-align: center">Content</a-card-grid> <a-card-grid style="width: 25%; text-align: center">Content</a-card-grid> <a-card-grid style="width: 25%; text-align: center">Content</a-card-grid> <a-card-grid style="width: 25%; text-align: center">Content</a-card-grid> <a-card-grid style="width: 25%; text-align: center">Content</a-card-grid> <a-card-grid style="width: 25%; text-align: center">Content</a-card-grid> </a-card></template>
内部卡片
可以放在普通卡片内部,展示多层级结构的信息
<template> <a-card title="Card title"> <p style="font-size: 14px; color: rgba(0, 0, 0, 0.85); margin-bottom: 16px; font-weight: 500"> Group title </p> <a-card title="Inner card title"> <template #extra> <a href="#">More</a> </template> Inner Card content </a-card> <a-card title="Inner card title" :style="{ marginTop: '16px' }"> <template #extra> <a href="#">More</a> </template> Inner Card content </a-card> </a-card></template>
支持更多内容配置
一种支持封面、头像、标题和描述信息的卡片。
<template> <a-card hoverable style="width: 300px"> <template #cover> <img alt="example" src="https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png" /> </template> <template class="ant-card-actions" #actions> <setting-outlined key="setting" /> <edit-outlined key="edit" /> <ellipsis-outlined key="ellipsis" /> </template> <a-card-meta title="Card title" description="This is the description"> <template #avatar> <a-avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" /> </template> </a-card-meta> </a-card></template><script lang="ts">import { SettingOutlined, EditOutlined, EllipsisOutlined } from '@ant-design/icons-vue';import { defineComponent } from 'vue';export default defineComponent({ components: { SettingOutlined, EditOutlined, EllipsisOutlined, },});</script>
带页签的卡片
可承载更多内容
<template> <a-card style="width: 100%" title="Card title" :tab-list="tabList" :active-tab-key="key" @tabChange="key => onTabChange(key, 'key')" > <template #customRender="item"> <span> <home-outlined /> {{ item.key }} </span> </template> <template #extra> <a href="#">More</a> </template> {{ contentList[key] }} </a-card> <br /> <br /> <a-card style="width: 100%" :tab-list="tabListNoTitle" :active-tab-key="noTitleKey" @tabChange="key => onTabChange(key, 'noTitleKey')" > <p v-if="noTitleKey === 'article'">article content</p> <p v-else-if="noTitleKey === 'app'">app content</p> <p v-else>project content</p> <template #tabBarExtraContent> <a href="#">More</a> </template> </a-card></template><script lang="ts">import { HomeOutlined } from '@ant-design/icons-vue';import { defineComponent, ref } from 'vue';export default defineComponent({ components: { HomeOutlined, }, setup() { const tabList = [ { key: 'tab1', // tab: 'tab1', slots: { tab: 'customRender' }, }, { key: 'tab2', tab: 'tab2', }, ]; const contentList = { tab1: 'content1', tab2: 'content2', }; const tabListNoTitle = [ { key: 'article', tab: 'article', }, { key: 'app', tab: 'app', }, { key: 'project', tab: 'project', }, ]; const key = ref('tab1'); const noTitleKey = ref('app'); const onTabChange = (value: string, type: string) => { console.log(value, type); if (type === 'key') { key.value = value; } else if (type === 'noTitleKey') { noTitleKey.value = value; } }; return { tabList, contentList, tabListNoTitle, key, noTitleKey, onTabChange, }; },});</script>
API
Card
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| actions | 卡片操作组,位置在卡片底部 | slots | - | |
|---|---|---|---|---|
| activeTabKey | 当前激活页签的 key | string | - | |
|---|---|---|---|---|
| headStyle | 自定义标题区域样式 | object | - | |
|---|---|---|---|---|
| bodyStyle | 内容区域自定义样式 | object | - | |
|---|---|---|---|---|
| bordered | 是否有边框 | boolean | true | |
|---|---|---|---|---|
| cover | 卡片封面 | slot | - | |
|---|---|---|---|---|
| defaultActiveTabKey | 初始化选中页签的 key,如果没有设置 activeTabKey | string | 第一个页签 | |
|---|---|---|---|---|
| extra | 卡片右上角的操作区域 | string|slot | - | | |---|---|---|---|---|
| hoverable | 鼠标移过时可浮起 | boolean | false | |
|---|---|---|---|---|
| loading | 当卡片内容还在加载中时,可以用 loading 展示一个占位 | boolean | false | |
|---|---|---|---|---|
| tabList | 页签标题列表, 可以通过 slots 属性自定义 tab | Array<{key: string, tab: any, slots: {tab: ‘XXX’}}> | - | |
|---|---|---|---|---|
| tabBarExtraContent | tab bar 上额外的元素 | slot | 无 | 1.5.0 |
|---|---|---|---|---|
| size | card 的尺寸 | default | small | default | | |---|---|---|---|---|
| title | 卡片标题 | string|slot | - | | |---|---|---|---|---|
| type | 卡片类型,可设置为 inner 或 不设置 | string | - | |
|---|---|---|---|---|
事件
| 事件名称 | 说明 | 回调参数 | 版本 |
|---|---|---|---|
| tabChange | 页签切换的回调 | (key) => void | - |
|---|---|---|---|
Card.Grid
Card.Meta
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| avatar | 头像/图标 | slot | - | |
|---|---|---|---|---|
