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 | 左侧图片 URL | string | - |
| title | 标题 | string | - |
| desc | 描述 | string | - |
| tag | 图片角标 | string | - |
| num | 商品数量 | number | string | - |
| price | 商品价格 | number | string | - |
| origin-price | 商品划线原价 | number | string | - |
| currency | 货币符号 | string | ¥ |
| centered | 内容是否垂直居中 | boolean | false |
| thumb-link | 点击左侧图片后跳转的链接地址 | string | - |
| lazy-load | 是否开启图片懒加载,须配合 Lazyload 组件使用 | boolean | false |
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-padding | var(--van-padding-xs) var(--van-padding-md) | 商品卡片的内边距 |
| --van-card-font-size | var(--van-font-size-sm) | 商品卡片的字体大小 |
| --van-card-text-color | var(--van-text-color) | 商品卡片的文字颜色 |
| --van-card-background | var(--van-background) | 商品卡片的背景色 |
| --van-card-thumb-size | 88px | 缩略图的尺寸 |
| --van-card-thumb-radius | var(--van-radius-lg) | 缩略图的圆角大小 |
| --van-card-title-line-height | 16px | 标题的行高 |
| --van-card-desc-color | var(--van-text-color-2) | 描述文字的颜色 |
| --van-card-desc-line-height | var(--van-line-height-md) | 描述文字的行高 |
| --van-card-price-color | var(--van-text-color) | 价格的文字颜色 |
| --van-card-origin-price-color | var(--van-text-color-2) | 原价的文字颜色 |
| --van-card-num-color | var(--van-text-color-2) | 数量的文字颜色 |
| --van-card-origin-price-font-size | var(--van-font-size-xs) | 原价的字体大小 |
| --van-card-price-font-size | var(--van-font-size-sm) | 价格的字体大小 |
| --van-card-price-integer-font-size | var(--van-font-size-lg) | 价格整数部分的字体大小 |
| --van-card-price-font | var(--van-price-font) | 价格的字体 |
