Skip to content

Card 商品卡片

介绍

商品卡片,用于展示商品的图片、价格等信息。

引入

js
import { createApp } from 'vue';
import { Card } from '@szhn/dh-design-mobile';

const app = createApp();
app.use(Card);

代码演示

基础用法

基础用法展示商品的缩略图、标题、价格等信息。

html
<van-card
  num="2"
  price="2.00"
  title="商品标题"
  desc="描述信息"
  thumb="https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg"
/>

高级用法

可以通过插槽添加定制内容。

html
<van-card
  num="2"
  tag="标签"
  price="2.00"
  origin-price="10.00"
  title="商品标题"
  desc="描述信息"
  thumb="https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg"
>
  <template #tags>
    <van-tag plain type="primary">标签</van-tag>
    <van-tag plain type="primary">标签</van-tag>
  </template>
  <template #footer>
    <van-button size="mini">按钮</van-button>
    <van-button size="mini">按钮</van-button>
  </template>
</van-card>

API

Props

参数说明类型默认值
thumb左侧图片 URLstring-
title标题string-
desc描述string-
tag图片角标string-
num商品数量number | string-
price商品价格number | string-
origin-price商品划线原价number | string-
currency货币符号string¥
centered内容是否垂直居中booleanfalse
thumb-link点击左侧图片后跳转的链接地址string-
lazy-load是否开启图片懒加载,须配合 Lazyload 组件使用booleanfalse

Events

事件名说明回调参数
click点击时触发event: MouseEvent
click-thumb点击自定义图片时触发event: MouseEvent

Slots

名称说明
title自定义标题
desc自定义描述
num自定义数量
price自定义价格
origin-price自定义商品原价
price-top自定义价格上方区域
bottom自定义价格下方区域
thumb自定义图片
tag自定义图片角标
tags自定义描述下方标签区域
footer自定义右下角内容

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 组件。

名称默认值描述
--van-card-paddingvar(--van-padding-xs) var(--van-padding-md)商品卡片的内边距
--van-card-font-sizevar(--van-font-size-sm)商品卡片的字体大小
--van-card-text-colorvar(--van-text-color)商品卡片的文字颜色
--van-card-backgroundvar(--van-background)商品卡片的背景色
--van-card-thumb-size88px缩略图的尺寸
--van-card-thumb-radiusvar(--van-radius-lg)缩略图的圆角大小
--van-card-title-line-height16px标题的行高
--van-card-desc-colorvar(--van-text-color-2)描述文字的颜色
--van-card-desc-line-heightvar(--van-line-height-md)描述文字的行高
--van-card-price-colorvar(--van-text-color)价格的文字颜色
--van-card-origin-price-colorvar(--van-text-color-2)原价的文字颜色
--van-card-num-colorvar(--van-text-color-2)数量的文字颜色
--van-card-origin-price-font-sizevar(--van-font-size-xs)原价的字体大小
--van-card-price-font-sizevar(--van-font-size-sm)价格的字体大小
--van-card-price-integer-font-sizevar(--van-font-size-lg)价格整数部分的字体大小
--van-card-price-fontvar(--van-price-font)价格的字体