Vant4 Card 商品卡片

2023-02-16 17:57 更新

介紹

商品卡片,用于展示商品的圖片、價(jià)格等信息。

引入

通過以下方式來(lái)全局注冊(cè)組件,更多注冊(cè)方式請(qǐng)參考組件注冊(cè)。

import { createApp } from 'vue';
import { Card } from 'vant';

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

代碼演示

基礎(chǔ)用法

<van-card
  num="2"
  price="2.00"
  desc="描述信息"
  title="商品標(biāo)題"
  thumb="https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg"
/>

營(yíng)銷信息

通過 ?origin-price? 設(shè)置商品原價(jià),通過 ?tag? 設(shè)置商品左上角標(biāo)簽。

<van-card
  num="2"
  tag="標(biāo)簽"
  price="2.00"
  desc="描述信息"
  title="商品標(biāo)題"
  thumb="https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg"
  origin-price="10.00"
/>

自定義內(nèi)容

?Card? 組件提供了多個(gè)插槽,可以靈活地自定義內(nèi)容。

<van-card
  num="2"
  price="2.00"
  desc="描述信息"
  title="商品標(biāo)題"
  thumb="https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg"
>
  <template #tags>
    <van-tag plain type="primary">標(biāo)簽</van-tag>
    <van-tag plain type="primary">標(biāo)簽</van-tag>
  </template>
  <template #footer>
    <van-button size="mini">按鈕</van-button>
    <van-button size="mini">按鈕</van-button>
  </template>
</van-card>

API

Props

參數(shù) 說(shuō)明 類型 默認(rèn)值
thumb 左側(cè)圖片 URL string -
title 標(biāo)題 string -
desc 描述 string -
tag 圖片角標(biāo) string -
num 商品數(shù)量 number | string -
price 商品價(jià)格 number | string -
origin-price 商品劃線原價(jià) number | string -
centered 內(nèi)容是否垂直居中 boolean false
currency 貨幣符號(hào) string
thumb-link 點(diǎn)擊左側(cè)圖片后跳轉(zhuǎn)的鏈接地址 string -
lazy-load 是否開啟圖片懶加載,須配合 Lazyload 組件使用 boolean false

Events

事件名 說(shuō)明 回調(diào)參數(shù)
click 點(diǎn)擊時(shí)觸發(fā) event: MouseEvent
click-thumb 點(diǎn)擊自定義圖片時(shí)觸發(fā) event: MouseEvent

Slots

名稱 說(shuō)明
title 自定義標(biāo)題
desc 自定義描述
num 自定義數(shù)量
price 自定義價(jià)格
origin-price 自定義商品原價(jià)
price-top 自定義價(jià)格上方區(qū)域
bottom 自定義價(jià)格下方區(qū)域
thumb 自定義圖片
tag 自定義圖片角標(biāo)
tags 自定義描述下方標(biāo)簽區(qū)域
footer 自定義右下角內(nèi)容

類型定義

組件導(dǎo)出以下類型定義:

import type { CardProps } from 'vant';

主題定制

樣式變量

組件提供了下列 CSS 變量,可用于自定義樣式,使用方法請(qǐng)參考 ConfigProvider 組件。

名稱 默認(rèn)值 描述
--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) -


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)