Skip to content

Card 卡片

通用卡片容器。

何时使用

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

典型卡片

包含标题、内容、操作区域。

vue
<template>
  <g-card title="Card title" style="width: 300px">
    <template #extra><a href="#">More</a></template>
    <p>Card content</p>
    <p>Card content</p>
    <p>Card content</p>
  </g-card>
</template>

无边框

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

vue
<template>
  <div style="background: #ececec; padding: 30px">
    <g-card title="Card title" :bordered="false" style="width: 300px">
      <p>Card content</p>
      <p>Card content</p>
      <p>Card content</p>
    </g-card>
  </div>
</template>

简洁卡片

只包含内容区域。

vue
<template>
  <g-card style="width: 300px">
    <p>Card content</p>
    <p>Card content</p>
    <p>Card content</p>
  </g-card>
</template>

更灵活的内容展示

可以调整默认边距,设定宽度。

vue
<template>
  <g-card title="Card title" :body-style="{ padding: '24px' }" style="width: 300px">
    <template #extra><a href="#">More</a></template>
    <p>Card content</p>
    <p>Card content</p>
    <p>Card content</p>
  </g-card>
</template>

栅格卡片

在系统概览页面常常和栅格进行配合。

vue
<template>
  <div style="background: #ececec; padding: 30px">
    <g-row :gutter="16">
      <g-col :span="8">
        <g-card title="Card title" :bordered="false">
          <p>Card content</p>
        </g-card>
      </g-col>
      <g-col :span="8">
        <g-card title="Card title" :bordered="false">
          <p>Card content</p>
        </g-card>
      </g-col>
      <g-col :span="8">
        <g-card title="Card title" :bordered="false">
          <p>Card content</p>
        </g-card>
      </g-col>
    </g-row>
  </div>
</template>

预加载的卡片

数据读入前会有文本块样式。

vue
<template>
  <div>
    <g-switch v-model:checked="loading" />
    <g-card style="width: 300px; margin-top: 16px" :loading="loading">
      <template #actions>
        <g-icon key="setting" type="setting" />
        <g-icon key="edit" type="edit" />
        <g-icon key="ellipsis" type="ellipsis" />
      </template>
      <g-card-meta
        title="Card title"
        description="This is the description"
      >
        <template #avatar>
          <g-avatar src="https://joeschmoe.io/api/v1/random" />
        </template>
      </g-card-meta>
    </g-card>
  </div>
</template>

<script>
import { ref } from 'vue'

export default {
  setup() {
    const loading = ref(true)
    
    return {
      loading
    }
  }
}
</script>

带页签的卡片

可承载更多内容。

vue
<template>
  <div>
    <g-card
      style="width: 100%"
      title="Card title"
      :tab-list="tabList"
      :active-tab-key="key"
      @tabChange="onTabChange"
    >
      <span v-if="key === 'tab1'">content1</span>
      <span v-else-if="key === 'tab2'">content2</span>
      <span v-else>no-title</span>
    </g-card>
    <br /><br />
    <g-card
      style="width: 100%"
      :tab-list="tabListNoTitle"
      :active-tab-key="noTitleKey"
      @tabChange="onTabChange2"
    >
      <p v-if="noTitleKey === 'article'">article content</p>
      <p v-else-if="noTitleKey === 'app'">app content</p>
      <p v-else>project content</p>
    </g-card>
  </div>
</template>

<script>
import { ref } from 'vue'

export default {
  setup() {
    const tabList = [
      {
        key: 'tab1',
        tab: 'tab1',
      },
      {
        key: 'tab2',
        tab: 'tab2',
      },
    ]
    
    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) => {
      console.log(value)
      key.value = value
    }
    
    const onTabChange2 = (value) => {
      console.log(value)
      noTitleKey.value = value
    }
    
    return {
      tabList,
      tabListNoTitle,
      key,
      noTitleKey,
      onTabChange,
      onTabChange2
    }
  }
}
</script>

内部卡片

可以放在普通卡片内部,展示多层级结构的信息。

vue
<template>
  <g-card title="Card title">
    <g-card
      type="inner"
      title="Inner Card title"
      :extra="extra"
    >
      Inner Card content
    </g-card>
    <g-card
      style="margin-top: 16px"
      type="inner"
      title="Inner Card title"
      :extra="extra"
    >
      Inner Card content
    </g-card>
  </g-card>
</template>

<script>
import { h } from 'vue'

export default {
  setup() {
    const extra = h('a', { href: '#' }, 'More')
    
    return {
      extra
    }
  }
}
</script>

支持更多内容配置

一种支持封面、头像、标题和描述信息的卡片。

vue
<template>
  <g-card
    hoverable
    style="width: 240px"
    cover="https://os.alipayobjects.com/rmsportal/QBnOOoLaAfKPirc.png"
  >
    <template #actions>
      <g-icon key="setting" type="setting" />
      <g-icon key="edit" type="edit" />
      <g-icon key="ellipsis" type="ellipsis" />
    </template>
    <g-card-meta title="Europe Street beat" description="www.instagram.com">
      <template #avatar>
        <g-avatar src="https://joeschmoe.io/api/v1/random" />
      </template>
    </g-card-meta>
  </g-card>
</template>

网格型内嵌卡片

一种常见的卡片内容区隔模式。

vue
<template>
  <g-card title="Card Title">
    <div class="card-container">
      <div class="card-item">
        <p>content1</p>
      </div>
      <div class="card-item">
        <p>content2</p>
      </div>
      <div class="card-item">
        <p>content3</p>
      </div>
      <div class="card-item">
        <p>content4</p>
      </div>
      <div class="card-item">
        <p>content5</p>
      </div>
      <div class="card-item">
        <p>content6</p>
      </div>
      <div class="card-item">
        <p>content7</p>
      </div>
    </div>
  </g-card>
</template>

<style>
.card-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.card-item {
  text-align: center;
  color: rgba(0, 0, 0, 0.85);
  background: #fafafa;
  border-radius: 4px;
  min-height: 30px;
  line-height: 30px;
}
</style>

API

Card

参数说明类型默认值版本
actions卡片操作组,位置在卡片底部slots-
activeTabKey当前激活页签的 keystring-
bodyStyle内容区域自定义样式object-
bordered是否有边框booleantrue
cover卡片封面string | slot-
defaultActiveTabKey初始化选中页签的 key,如果没有设置 activeTabKeystring第一个页签
extra卡片右上角的操作区域string | slot-
headStyle自定义标题区域样式object-
hoverable鼠标移过时可浮起booleanfalse
loading当卡片内容还在加载中时,可以用 loading 展示一个占位booleanfalse
sizecard 的尺寸default | smalldefault
tabBarExtraContenttab bar 上额外的元素slot-
tabList页签标题列表Array<{key: string, tab: any}>-
tabPropsTabs--
title卡片标题string | slot-
type卡片类型,可设置为 inner 或 不设置string-

Card 事件

事件名称说明回调参数
tabChange页签切换的回调(key) => void

Card.Grid

参数说明类型默认值
class网格容器类名string-
hoverable鼠标移过时可浮起booleantrue
style定义网格容器类名的样式object-

Card.Meta

参数说明类型默认值版本
avatar头像/图标slot-
description描述内容string | slot-
title标题内容string | slot-

Released under the MIT License.