Skip to content

卡片 Card

通用卡片容器

何时使用

  • 最基础的卡片容器,可承载文字、列表、图片、段落,常用于后台概览页面

基本使用

Default size card

card content

card content

card content

Show Code
vue
<template>
  <Card title="Default size card" :width="300">
    <template #extra>
      <a href="#">more</a>
    </template>
    <p>card content</p>
    <p>card content</p>
    <p>card content</p>
  </Card>
</template>

在灰色背景上使用无边框的卡片

Card title

Card content

Card content

Card content

Show Code
vue
<template>
  <div style="display: inline-block; background: #ececec; padding: 30px; border-radius: 8px;">
    <Card title="Card title" :bordered="false" :width="300">
      <p>Card content</p>
      <p>Card content</p>
      <p>Card content</p>
    </Card>
  </div>
</template>

简洁卡片

Card content

Card content

Card content

Show Code
vue
<template>
  <Card :width="300">
    <p>Card content</p>
    <p>Card content</p>
    <p>Card content</p>
  </Card>
</template>

三种尺寸

small
middle
large
MIDDLE size card

card content

card content

card content

Show Code
vue
<script setup lang="ts">
import { ref } from 'vue'
const sizeOptions = [
  {
    label: 'small',
    value: 'small'
  },
  {
    label: 'middle',
    value: 'middle'
  },
  {
    label: 'large',
    value: 'large'
  }
]
const cardWidth = {
  small: 240,
  middle: 300,
  large: 360
}
const size = ref('middle')
</script>
<template>
  <Space vertical>
    <Radio :options="sizeOptions" v-model:value="size" button button-style="solid" />
    <Card :size="size" :title="`${size.toUpperCase()} size card`" :width="cardWidth[size as keyof typeof cardWidth]">
      <template #extra>
        <a href="#">more</a>
      </template>
      <p>card content</p>
      <p>card content</p>
      <p>card content</p>
    </Card>
  </Space>
</template>

鼠标移过时可浮起

Card title

Card content

Card content

Card content

Show Code
vue
<template>
  <Card hoverable title="Card title" :width="300">
    <p>Card content</p>
    <p>Card content</p>
    <p>Card content</p>
  </Card>
</template>

预加载卡片

Loading State:
Card title
Show Code
vue
<script setup lang="ts">
import { ref } from 'vue'
const loading = ref(true)
</script>
<template>
  <Space vertical>
    <Space align="center">Loading State:<Switch v-model="loading" /></Space>
    <Card :loading="loading" title="Card title" :width="300">
      <p>Card content</p>
      <p>Card content</p>
      <p>Card content</p>
    </Card>
  </Space>
</template>

自定义样式

Default size card

card content

card content

card content

Show Code
vue
<template>
  <Card
    title="Default size card"
    :width="300"
    :headStyle="{ fontSize: '18px', color: '#fff', backgroundColor: '#1677ff'}"
    :bodyStyle="{ fontSize: '16px', color: '#fff', backgroundColor: '#52c41a'}">
    <template #extra><a href="#">more</a></template>
    <p>card content</p>
    <p>card content</p>
    <p>card content</p>
  </Card>
</template>

内部嵌套卡片

Card title

Group title

Inner card title
Inner Card content
Inner card title
Inner Card content
Show Code
vue
<template>
  <Card title="Card title" :width="360">
    <p style="font-size: 14px; color: rgba(0, 0, 0, 0.85); margin-bottom: 16px; font-weight: 500;">
      Group title
    </p>
    <Card title="Inner card title">
      <template #extra>
        <a href="#">More</a>
      </template>
      Inner Card content
    </Card>
    <Card title="Inner card title" :style="{ marginTop: '16px' }">
      <template #extra>
        <a href="#">More</a>
      </template>
      Inner Card content
    </Card>
  </Card>
</template>

栅格卡片

Show Code
vue
<template>
  <div style="background-color: #ececec; padding: 20px; border-radius: 8px;">
    <Row :gutter="16">
      <Col :span="8">
        <Card title="Card title" :bordered="false">
          <p>card content</p>
        </Card>
      </Col>
      <Col :span="8">
        <Card title="Card title" :bordered="false">
          <p>card content</p>
        </Card>
      </Col>
      <Col :span="8">
        <Card title="Card title" :bordered="false">
          <p>card content</p>
        </Card>
      </Col>
    </Row>
  </div>
</template>

APIs

Card

参数说明类型默认值
width卡片宽度,单位 pxnumber | string'auto'
bordered是否有边框booleantrue
size卡片的尺寸'small' | 'middle' | 'large''middle'
hoverable鼠标移过时可浮起booleanfalse
loading当卡片内容还在加载中时,可以用 loading 展示一个占位booleanfalse
skeletonProps加载中时,骨架屏的属性配置,参考 Skeleton Propsobject{}
title卡片标题string | slotundefined
extra卡片右上角的操作区域string | slotundefined
headStyle自定义标题区域样式CSSProperties{}
bodyStyle自定义内容区域样式CSSProperties{}

Released under the MIT License.