Skip to content

Card 卡片 ​

查看 sn-card 的 2.0 版本差异

基础用法 ​

通用内容卡片容器,用于收纳展示一组相关信息。

  • 支持标题与章节标符,头部 / 尾部区域按内容有无自动显隐
  • 提供头部、尾部与操作栏插槽
  • 支持自定义边框样式
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自定义卡片根节点样式SnStyleValue''-
titleStyle自定义标题文本样式SnStyleValue''-
titleClass标题文本外部类String''-
headerClass标题栏外部类String''-
headerStyle自定义标题栏样式SnStyleValue''-
footerClass尾部区域外部类String''-
footerStyle自定义尾部区域样式SnStyleValue''-
actionClass操作栏外部类String''-
actionStyle自定义操作栏样式SnStyleValue''-

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

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

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

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

头像形状:方形 / 圆形。

可选值备注
square方形
circle圆形

插槽 ​

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

使用 MIT 协议