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>應付: {{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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
vue3實現(xiàn)動態(tài)側邊菜單欄的幾種方式簡單總結
在做開發(fā)中都會遇到的需求,每個用戶的權限是不一樣的,那他可以訪問的頁面(路由)可以操作的菜單選項是不一樣的,如果由后端控制,我們前端需要去實現(xiàn)動態(tài)路由,動態(tài)渲染側邊菜單欄,這篇文章主要給大家介紹了關于vue3實現(xiàn)動態(tài)側邊菜單欄的幾種方式,需要的朋友可以參考下2024-02-02
使用Bootstrap + Vue.js實現(xiàn)添加刪除數(shù)據(jù)示例
本篇文章主要介紹了使用Bootstrap + Vue.js實現(xiàn) 添加刪除數(shù)據(jù)示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-02-02
vue前端和Django后端如何查詢一定時間段內(nèi)的數(shù)據(jù)
這篇文章主要給大家介紹了關于vue前端和Django后端如何查詢一定時間段內(nèi)的數(shù)據(jù)的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-02-02
vue-admin-template?動態(tài)路由的實現(xiàn)示例
本文主要介紹了ue-admin-template動態(tài)路由的實現(xiàn),文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-12-12

