Skip to content

Coupon - Vant 4

Coupon ​

Intro ​

Used for redemption and selection of coupons.

Install ​

Register component globally via app.use, refer to Component Registration for more registration ways.

js
import { createApp } from'vue'; import { CouponCell, CouponList } from'vant'; const app = createApp(); app.use(CouponCell); app.use(CouponList);

Usage ​

Basic Usage ​

html
js
import { ref } from'vue'; exportdefault { setup() { const coupon = { available: 1, originCondition: 0, reason: '', value: 150, name: 'Coupon name', startAt: 1489104000, endAt: 1514592000, valueDesc: '1.5', unitDesc: 'Ԫ', }; const coupons = ref([coupon]); const showList = ref(false); const chosenCoupon = ref(-1); constonChange = (index) => { showList.value = false; chosenCoupon.value = index; }; constonExchange = (code) => { coupons.value.push(coupon); }; return { coupons, showList, onChange, onExchange, chosenCoupon, disabledCoupons: [coupon], }; }, };

API ​

CouponCell Props ​

AttributeDescriptionTypeDefault
titleCell titlestringCoupon
chosen-couponIndex of chosen coupon*numbernumber[]*
couponsCoupon listCoupon[][]
editableCell editablebooleantrue
borderWhether to show inner borderbooleantrue
currencyCurrency symbolstring��

CouponList Props ​

AttributeDescriptionTypeDefault
v-modelCurrent exchange codestring-
chosen-couponIndex of chosen coupons, support multiple selection (type is [])*numbernumber[]*
couponsCoupon listCouponInfo[][]
disabled-couponsDisabled coupon listCouponInfo[][]
enabled-titleTitle of coupon liststringAvailable
disabled-titleTitle of disabled coupon liststringUnavailable
exchange-button-textExchange button textstringExchange
exchange-button-loadingWhether to show loading in exchange buttonbooleanfalse
exchange-button-disabledWhether to disable exchange buttonbooleanfalse
exchange-min-lengthMin length to enable exchange buttonnumber1
displayed-coupon-indexIndex of displayed couponnumber-
close-button-textClose button textstringClose
input-placeholderInput placeholderstringCoupon code
currencyCurrency symbolstring��
empty-imagePlaceholder image when list is emptystring-
show-countWhether to show coupon count in tab titlebooleantrue

CouponList Events ​

EventDescriptionArguments
changeEmitted when chosen coupon changedindex: index of chosen coupon
exchangeEmitted when exchanging couponcode: exchange code

CouponList Slots ​

NameDescription
list-footerCoupon list bottom
disabled-list-footerUnavailable coupons list bottom
list-buttonCustomize the bottom button

Data Structure of CouponInfo ​

KeyDescriptionType
idIdstring
nameNamestring
conditionConditionstring
startAtStart time (Timestamp, unit second)number
endAtEnd time (Timestamp, unit second)number
descriptionDescriptionstring
reasonUnavailable reasonstring
valueValuenumber
valueDescValue Textstring
unitDescUnit Textstring

Types ​

The component exports the following type definitions:

ts
importtype { CouponCellProps, CouponListProps, CouponInfo } from'vant';

Theming ​

CSS Variables ​

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-coupon-margin0 var(--van-padding-sm) var(--van-padding-sm)-
--van-coupon-content-height84px-
--van-coupon-content-padding14px 0-
--van-coupon-content-text-colorvar(--van-text-color)-
--van-coupon-backgroundvar(--van-background-2)-
--van-coupon-active-backgroundvar(--van-active-color)-
--van-coupon-radiusvar(--van-radius-lg)-
--van-coupon-shadow0 0 4px rgba(0, 0, 0, 0.1)-
--van-coupon-head-width96px-
--van-coupon-amount-colorvar(--van-danger-color)-
--van-coupon-amount-font-size30px-
--van-coupon-currency-font-size40%-
--van-coupon-name-font-sizevar(--van-font-size-md)-
--van-coupon-disabled-text-colorvar(--van-text-color-2)-
--van-coupon-description-paddingvar(--van-padding-xs) var(--van-padding-md)-
--van-coupon-description-border-colorvar(--van-border-color)-
--van-coupon-checkbox-colorvar(--van-danger-color)-
--van-coupon-list-backgroundvar(--van-background)-
--van-coupon-list-field-padding5px 0 5px var(--van-padding-md)-
--van-coupon-list-exchange-button-height32px-
--van-coupon-list-close-button-height40px-
--van-coupon-list-empty-tip-colorvar(--van-text-color-2)-
--van-coupon-list-empty-tip-font-sizevar(--van-font-size-md)-
--van-coupon-list-empty-tip-line-heightvar(--van-line-height-md)-
--van-coupon-cell-selected-text-colorvar(--van-text-color)-

Enterprise-level mobile solution based on Vant