vant coupon组件使用完整demo不坑人

前言:用到优惠券选择组件,vant官网demo很不友好。百度了下,不少网友都是片段,都是做技术的,就不能贴个完整的么?给个demo让别人一个劲儿的找bug完善。

这里就直接贴完整demo了,组件注册全部局部注册。

 

 

示例代码:

复制代码
 1 <template>
 2   <div>
 3     <!-- 优惠券单元格 -->
 4     <van-coupon-cell :coupons="coupons" :chosen-coupon="chosenCoupon" @click="showList = true" />
 5 
 6     <!-- 优惠券列表 -->
 7     <van-popup v-model="showList" position="bottom">
 8       <van-coupon-list :coupons="coupons" :chosen-coupon="chosenCoupon" :disabled-coupons="disabledCoupons" @change="onChange" @exchange="onExchange" />
 9     </van-popup>
10   </div>
11 </template>
12 <script>
13 const coupon = {
14   id: '1', // 优惠券id
15   discount: 0, // 折扣券 折值 整数 为0不显示折
16   denominations: 2000, // 优惠券金额 单位分
17   originCondition: 5000, // 满减规则金额 单位分 为0显示无门槛
18   value: 12, // 折扣券优惠金额,单位分
19   name: '新人大礼包', // 优惠券名称
20   description: '喜欢你就用', // 描述信息
21   reason: '订单未满200元', // 不可用原因,优惠券不可用时展示
22   startAt: parseInt(1556337595530 / 1000), // 卡有效开始时间 (时间戳, 单位秒)
23   endAt: parseInt(1559337595530 / 1000) // 卡失效日期 (时间戳, 单位秒)
24 }
25 
26 import { CouponCell, CouponList,Popup  } from 'vant';
27 export default {
28   components: {
29     [CouponCell.name]: CouponCell,
30     [CouponList.name]: CouponList,
31     [Popup.name]: Popup
32   },
33   data() {
34     return {
35       showList:false,
36       chosenCoupon: -1,
37       coupons: [coupon],
38       disabledCoupons: [coupon]
39     };
40   },
41 
42   methods: {
43     onChange(index) {
44       this.showList = false;
45       this.chosenCoupon = index;
46     },
47     onExchange(code) {
48       this.coupons.push(coupon);
49     }
50   }
51 };
52 </script>
复制代码

注:其中的 coupon  可以改成pros传过来,原来的数据可以在引用页面或者组件中进行数据结构转换,页面直接引用就好了。

posted on   逍遥云天  阅读(1135)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
历史上的今天:
2020-04-01 支付宝小程序使用canvas画布模拟页面截屏并分享的实现
2020-04-01 微信小程序全局分享转发控制实现——从此无需页面单独配置
2019-04-01 编写高效的 CSS 选择器
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示