Skip to content

Card 卡片

查看 sn-card 的 2.0 版本差异

基础用法

  • 用于收纳展示一组相关信息,是页面中最常用的内容容器。
  • title 设置卡片标题,默认插槽放置主体内容;section 开启标题左侧主题色章节标符。
  • 头部区域仅在 title 不为空、使用 title 插槽、配置了头像(avatar-configavatar 插槽)或使用 header-extra 插槽时才渲染。
  • footer 插槽放置尾部内容,action 插槽放置操作栏内容(默认右对齐),有内容时才渲染。
  • border 按"宽度 样式 颜色"以空格分隔解析,设为 none 可去除边框。
vue
<template>
	<sn-card title="卡片标题">
		<sn-text>卡片内容,可以放置文本、图片、表单等任意内容。</sn-text>
	</sn-card>
</template>

更多演示请下载 demo 查看

头像卡片

通过 avatar-config 配置卡片头部头像,字段与 sn-avatar 组件属性对齐;也可使用 avatar 插槽完全自定义头像内容。

vue
<template>
	<sn-card title="团队空间" :avatar-config="avatarConfig">
		<sn-text>团队成员 128 人。</sn-text>
	</sn-card>
</template>

<script lang="uts" setup>
import type { SnAvatarConfig } from '@/uni_modules/sinle-ui/core/types/index.uts'

const avatarConfig = {
	mode: 'text',
	text: 'UI',
	shape: 'circle',
	bgColor: '$info'
} as SnAvatarConfig
</script>

属性

参数说明类型默认值可选值
title卡片标题String''-
titleColor卡片标题颜色String$title-
titleFont卡片标题字体String''-
titleSize卡片标题字体大小String | Number$16-
titleLines卡片标题最大显示行数,超出截断Number-1-
avatarConfig头像参数配置,字段与 sn-avatar 组件属性对齐SnAvatarConfig{}-
bgColor卡片背景颜色String$front-
border卡片边框样式,设为 none 时去除边框String1px solid $line-
boxShadow卡片阴影String''-
margin卡片外边距String10px 0-
padding卡片内边距String | Number$15-
borderRadius卡片圆角大小String | Number$12-
section是否显示标题左侧章节标符Booleanfalsetrue | false
sectionColor章节标符颜色String$primary-
customStyle自定义卡片根节点样式UTSJSONObject | String''-
titleStyle自定义标题文本样式UTSJSONObject | String''-
titleClass标题文本外部类String''-
headerClass标题栏外部类String''-
headerStyle自定义标题栏样式UTSJSONObject | String''-
footerClass尾部区域外部类String''-
footerStyle自定义尾部区域样式UTSJSONObject | String''-
actionClass操作栏外部类String''-
actionStyle自定义操作栏样式UTSJSONObject | String''-

内置 sn-avatar 的组件(如列表项、发布卡)可通过 avatarConfig 属性统一配置头像参数。

名称类型必填描述
modeSnAvatarMode显示模式,默认 image
srcString图片路径(modeimage 时生效)
textString文本内容(modetext 时生效)
iconString图标名(modeicon 时生效)
sizeString | Number尺寸大小
shapeSnAvatarShape形状
bgColorString背景颜色
textColorString文本颜色
iconColorString图标颜色
borderRadiusString | Number圆角大小
enablePreviewBoolean是否启用图片预览(modeimage 时生效)

头像显示模式:图片 / 文本 / 图标。

可选值备注
image图片
text文本
icon图标

头像形状:方形 / 圆形。

可选值备注
square方形
circle圆形

插槽

名称说明
default放置卡片主体内容
title替换默认的卡片标题文本
avatar替换默认头像,可放置头像、LOGO 等
header-extra标题栏扩展区域,可放置按钮、徽标等
footer放置卡片尾部内容
action放置卡片操作栏内容

使用 MIT 协议