Vue實現(xiàn)簡單的購物車案例
更新時間:2021年10月04日 09:48:12 作者:Nero09xx
這篇文章主要為大家詳細介紹了Vue實現(xiàn)簡單的購物車案例,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了Vue實現(xiàn)簡單的購物車案例的具體代碼,供大家參考,具體內(nèi)容如下
代碼:
<template> <div> <div> <span>手機: </span> <span>價格</span> <input type="number" v-model.number="phonePrice"> <span> 數(shù)量 </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> 數(shù)量 </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>優(yōu)惠: {{discounts}}元</p> <p>應(yīng)付: {{allPrice}}</p> </div> </div> </template> <script> export default { data () { return { phonePrice: '', // 手機單價 phoneCount: '', // 手機數(shù)量 computerPrice: '', // 電腦單價 computerCount: '', // 電腦數(shù)量 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>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
學(xué)習(xí)vue.js中class與style綁定
這篇文章主要和大家一起學(xué)習(xí)vue.js中class與style綁定操作,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-12-12Vue使用Proxy監(jiān)聽所有接口狀態(tài)的方法實現(xiàn)
這篇文章主要介紹了Vue使用Proxy監(jiān)聽所有接口狀態(tài)的方法實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06深入解析el-col-group強大且靈活的Element表格列組件
這篇文章主要為大家介紹了el-col-group強大且靈活的Element表格列組件深入解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-04-04