Skip to content

xtf-card

组件说明

xtf-card 是卡片容器组件,用于承载内容分组展示。支持多种视觉变体(浮起、描边、填充、扁平、玻璃、拟物)、渐变边框、骨架屏加载态、封面图和可点击交互,适用于商品卡片、信息列表和内容模块等场景。


基础用法

1. 最简示例

通过 titledesc 设置卡片标题和描述,默认内容通过默认插槽传入:

vue
<template>
  <xtf-card title="商品信息" desc="以下是商品的基本信息">
    <text>商品名称:无线蓝牙耳机</text>
  </xtf-card>
</template>

2. 视觉变体

通过 variant 切换卡片视觉风格:

vue
<template>
  <view style="display: flex; flex-direction: column; gap: 24rpx">
    <xtf-card title="浮起" variant="elevated" desc="默认样式,带阴影和边框">
      <text>浮起卡片内容</text>
    </xtf-card>
    <xtf-card title="描边" variant="outlined" desc="仅边框,无阴影">
      <text>描边卡片内容</text>
    </xtf-card>
    <xtf-card title="填充" variant="filled" desc="渐变背景,无边框">
      <text>填充卡片内容</text>
    </xtf-card>
    <xtf-card title="扁平" variant="flat" desc="纯色背景,无边框无阴影">
      <text>扁平卡片内容</text>
    </xtf-card>
    <xtf-card title="玻璃" variant="glass" desc="毛玻璃效果">
      <text>玻璃卡片内容</text>
    </xtf-card>
    <xtf-card title="拟物" variant="neomorphic" desc="拟物风格阴影">
      <text>拟物卡片内容</text>
    </xtf-card>
  </view>
</template>

3. 封面图与插槽

通过 cover 插槽添加封面图,通过 footer 插槽添加底部操作区:

vue
<template>
  <xtf-card title="精选推荐" desc="今日热门商品" variant="elevated" cover-height="280rpx">
    <template #cover>
      <image
        src="https://picsum.photos/600/300?random=30"
        mode="aspectFill"
        style="width: 100%; height: 100%"
      />
    </template>
    <text>高品质无线蓝牙耳机,续航持久,音质出色。</text>
    <template #footer>
      <view style="display: flex; justify-content: space-between; align-items: center">
        <text style="color: var(--xtf-color-danger); font-weight: 700; font-size: 36rpx">¥199</text>
        <xtf-button label="立即购买" size="sm" />
      </view>
    </template>
  </xtf-card>
</template>

4. 渐变边框与加载态

通过 borderGradient 启用渐变边框,通过 loading 显示骨架屏:

vue
<template>
  <view style="display: flex; flex-direction: column; gap: 24rpx">
    <xtf-card title="渐变边框" border-gradient>
      <text>带渐变边框的卡片</text>
    </xtf-card>
    <xtf-card title="加载中" :loading="true">
      <text>内容加载中...</text>
    </xtf-card>
  </view>
</template>

5. 可点击与内边距

通过 clickable 使卡片可点击,通过 padding 控制内边距,通过 radius 控制圆角:

vue
<template>
  <xtf-card
    title="点击卡片"
    desc="点击查看详情"
    variant="elevated"
    clickable
    padding="lg"
    radius="xl"
    @click="onClick"
  >
    <text>点击此卡片触发事件</text>
  </xtf-card>
</template>

<script>
export default {
  methods: {
    onClick() {
      uni.showToast({ title: '点击了卡片', icon: 'none' })
    }
  }
}
</script>

全部属性

属性类型默认值作用描述适用范围
titleString''卡片标题设置标题
descString''卡片描述文字设置描述
variantString'elevated'视觉变体:'elevated' / 'outlined' / 'filled' / 'flat' / 'glass' / 'neomorphic'(也兼容 'neo'切换视觉风格
elevationString | Number2阴影层级(0~8),elevated 变体生效调整阴影强度
paddingString'md'内边距:'none' / 'sm' / 'md' / 'lg'控制内边距
radiusString | Object'lg'圆角:'sm' / 'md' / 'lg' / 'xl',或对象 { topLeft, topRight, bottomRight, bottomLeft }控制圆角
loadingBooleanfalse是否显示骨架屏加载态加载中展示
borderGradientBoolean | Stringfalse是否启用渐变边框渐变边框效果
coverHeightString | Number'220rpx'封面区域最小高度控制封面高度
clickableBooleanfalse是否可点击,启用后点击有缩放反馈卡片可交互场景
hoverableBooleanfalse是否有悬浮上浮效果(不绑定点击事件)仅视觉提升
customClassString''自定义类名样式覆盖
customStyleString | Object''自定义样式动态样式覆盖

事件

事件名称触发时机回调参数参数说明
click点击卡片时触发(需 clickabletrue(event)原生点击事件对象

插槽

插槽名说明
cover卡片顶部封面区域。
header替换 titledesc 组成的头部。
默认插槽卡片主体内容。
footer卡片底部操作区。

主题说明

  • elevated 变体背景使用 var(--xtf-card-bg),边框使用 var(--xtf-card-border),阴影使用 var(--xtf-shadow-card)
  • outlined 变体背景使用 var(--xtf-color-surface),边框使用 var(--xtf-color-border)
  • filled 变体背景为 var(--xtf-color-surface)var(--xtf-color-surface-muted) 渐变
  • glass 变体背景使用 var(--xtf-popup-bg),模糊使用 var(--xtf-card-glass-blur),阴影使用 var(--xtf-shadow-glass)
  • neomorphic 变体阴影使用 var(--xtf-shadow-neo)
  • 阴影层级使用 var(--xtf-card-elevation1) ~ var(--xtf-card-elevation8)
  • 标题字体使用 var(--xtf-font-font-family-title),字重 700
  • 骨架屏闪光使用 var(--xtf-card-skeleton-shimmer)
  • 圆角使用 var(--xtf-radius-sm) ~ var(--xtf-radius-xl)
  • 悬浮上浮阴影使用 var(--xtf-card-shadow-hover)

如需全局调整主题,请在 xtf-config-provider 或主题配置中覆盖上述 CSS 变量。

MIT Licensed