Vue实现简单的购物车案例
程序员文章站
2022-06-24 21:10:39
本文实例为大家分享了vue实现简单的购物车案例的具体代码,供大家参考,具体内容如下代码:
本文实例为大家分享了vue实现简单的购物车案例的具体代码,供大家参考,具体内容如下
代码:
<template> <div> <div> <span>手机: </span> <span>价格</span> <input type="number" v-model.number="phoneprice"> <span> 数量 </span><input type="number" v-model.number="phonecount"> <span> 小计: </span><span>{{phonetotal}}元</span> </div> <div> <span>电脑: </span> <span>价格</span> <input type="number" v-model.number="computerprice"> <span> 数量 </span><input type="number" v-model.number="computercount"> <span> 小计: </span><span>{{computertotal}}元</span> </div> <div> <span>运费: </span><input type="number" v-model.number="freight"><span>元</span><br> <span>共计: {{total}}元</span> <p>优惠: {{discounts}}元</p> <p>应付: {{allprice}}</p> </div> </div> </template> <script> export default { data () { return { phoneprice: '', // 手机单价 phonecount: '', // 手机数量 computerprice: '', // 电脑单价 computercount: '', // 电脑数量 freight: '', // 运费 discounts: '' } }, computed: { phonetotal () { return this.phoneprice * this.phonecount }, computertotal () { return this.computerprice * this.computercount }, // 总价 total () { return this.computertotal + this.phonetotal + this.freight }, allprice () { return this.total - this.discounts } }, watch: { total: { depp: true, handler () { if (this.phonetotal + this.computertotal > 5000 && this.phonetotal + this.computertotal < 8000) { this.discounts = 100 } else if (this.phonetotal + this.computertotal > 8000) { this.discounts = 200 } } } } } </script> <style scoped lang='less'> </style>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: 羊杂如何清洗干净
下一篇: Linux下 SSH远程管理服务