vue簡(jiǎn)單實(shí)現(xiàn)購(gòu)物車結(jié)算功能
本文實(shí)例為大家分享了vue簡(jiǎn)單實(shí)現(xiàn)購(gòu)物車結(jié)算的具體代碼,供大家參考,具體內(nèi)容如下

樣式?jīng)]有寫
<template>
?<div class="about container">
? ?<button class="btn btn-default">
? ? ?<router-link to="/customers">返回主頁(yè)</router-link>
? ?</button>
? ?<button>獲取數(shù)據(jù)</button>
? ?<ul>
? ? ?<li v-for="(item,index) in this.list" :key="index">
? ? ? ?<div>
? ? ? ? ?<input type="checkbox" v-model="item.checked" />
? ? ? ? ?<span>{{item.title}}</span>
? ? ? ? ?<button class="btn btn-default" @click="reduce(index)">-</button>
? ? ? ? ?<span>{{item.num}}</span>
? ? ? ? ?<button class="btn btn-default" @click="add(index)">+</button>
? ? ? ? ?<span>價(jià)格:{{item.price}}</span>
? ? ? ? ?<button @click="del(index,item._id)" class="btn btn-default">刪除</button>
? ? ? ?</div>
? ? ?</li>
? ?</ul>
? ?<input type="checkbox" v-model="allcheck" @click="checkall" />
? ?<button>合計(jì):{{totalMoney}}</button>
?</div>
</template>
<script>
export default {
?name: "about",
?// 調(diào)用app.vue組件中的方法
?inject: ["reload"],
?data() {
? ?return {
? ? ?list: [],
? ? ?allcheck: false
? ?};
?},
?methods: {
? ?async getproduct() {
? ? ?const res = await this.$http.get("/goodslist");
? ? ?this.list = res.data;
? ? ?localStorage.setItem("shoppingcart", JSON.stringify(this.list));
? ? ?console.log(this.list);
? ?},
? ?add(i) {
? ? ?this.list[i].num++;
? ?},
? ?reduce(i) {
? ? ?if (this.list[i].num <= 1) {
? ? ? ?this.list[i].num = 0;
? ? ? ?return;
? ? ?}
? ? ?this.list[i].num--;
? ?},
? ?checkall() {
? ? ?// ? console.log(this.allcheck);
? ? ?console.log(event.target.checked);
? ? ?this.list.forEach(item => {
? ? ? ?item.checked = event.target.checked;
? ? ? ?// console.log(item._id)
? ? ?});
? ?},
? ?async del(i, id) {
? ? ?const res = await this.$http.delete("/delfile/" + id);
? ? ?console.log(res);
? ? ?this.reload();
? ?}
?},
?computed: {
? ?totalMoney() {
? ? ?let allmoney = 0;
? ? ?let isAllCheck = true;
? ? ?for (let i in this.list) {
? ? ? ?if (this.list[i].checked) {
? ? ? ? ?allmoney += this.list[i].price * this.list[i].num;
? ? ? ?} else {
? ? ? ? ?isAllCheck = false;
? ? ? ?}
? ? ?}
? ? ?this.allcheck == isAllCheck;
? ? ?return allmoney;
? ?}
?},
?created() {
? ?this.getproduct();
?}
};
</script>
<style>
li {
?list-style: none;
}
</style>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vuejs手把手教你寫一個(gè)完整的購(gòu)物車實(shí)例代碼
- 基于Vuejs實(shí)現(xiàn)購(gòu)物車功能
- vue實(shí)現(xiàn)購(gòu)物車小案例
- Vue實(shí)現(xiàn)購(gòu)物車功能
- vue實(shí)現(xiàn)商城購(gòu)物車功能
- vue 實(shí)現(xiàn)購(gòu)物車總價(jià)計(jì)算
- vue+vant-UI框架實(shí)現(xiàn)購(gòu)物車的復(fù)選框全選和反選功能
- vuex實(shí)現(xiàn)的簡(jiǎn)單購(gòu)物車功能示例
- vue實(shí)現(xiàn)購(gòu)物車拋物線小球動(dòng)畫效果的方法詳解
- Vue實(shí)現(xiàn)購(gòu)物車詳情頁(yè)面的方法
相關(guān)文章
Vue+echart?展示后端獲取的數(shù)據(jù)實(shí)現(xiàn)
本文主要介紹了Vue+echart?展示后端獲取的數(shù)據(jù),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01
基于Vue實(shí)現(xiàn)一個(gè)textarea幽靈建議功能
不知道你有沒(méi)有發(fā)現(xiàn)Bing AI聊天有個(gè)輸入提示功能,在用戶輸入部分內(nèi)容時(shí)后面會(huì)給出灰色提示文案,用戶只要按下tab鍵就可以快速添加提示的后續(xù)內(nèi)容,我將這個(gè)功能稱為幽靈建議,接下來(lái)我將用Vue框架來(lái)實(shí)現(xiàn)這個(gè)功能,需要的朋友可以參考下2023-09-09
easycom模式開(kāi)發(fā)UNI-APP組件調(diào)用必須掌握的實(shí)用技巧
uni-app基于VUE開(kāi)發(fā),通常組件的使用都是先安裝,然后全局或者局部引入,注冊(cè),今天通過(guò)本文給大家分享easycom模式開(kāi)發(fā)UNI-APP組件調(diào)用必須掌握的實(shí)用技巧,需要的朋友一起看看吧2021-08-08
Vue2中使用自定義指令實(shí)現(xiàn)el-table虛擬列表的代碼示例
在實(shí)際開(kāi)發(fā)中,我們可能會(huì)面臨其他需求,例如在 el-table 中無(wú)法使用分頁(yè)技術(shù)的情況下展示海量數(shù)據(jù),這種情況下,頁(yè)面可能會(huì)出現(xiàn)卡頓,嚴(yán)重時(shí)甚至可能引發(fā)瀏覽器崩潰,所以針對(duì)這個(gè)問(wèn)題本文給大家介紹了vue2中使用自定義指令實(shí)現(xiàn)el-table虛擬列表,需要的朋友可以參考下2025-01-01
基于Vue3+UniApp在單個(gè)頁(yè)面實(shí)現(xiàn)固定TabBar的多種方式
tabBar 是移動(dòng)端應(yīng)用常見(jiàn)的頁(yè)面效果,用于實(shí)現(xiàn)多頁(yè)面的快速切換,本文給大家介紹了如何基于Vue3+UniApp在單個(gè)頁(yè)面實(shí)現(xiàn)固定TabBar的多種方式,需要的朋友可以參考下2025-03-03
vue-router路由參數(shù)刷新消失的問(wèn)題解決方法
本篇文章主要介紹了vue-router路由參數(shù)刷新消失的問(wèn)題解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
vue+elementUI封裝一個(gè)根據(jù)后端變化的動(dòng)態(tài)table(完整代碼)
這篇文章主要介紹了vue+elementUI,封裝一個(gè)根據(jù)后端變化的動(dòng)態(tài)table,實(shí)現(xiàn)了自動(dòng)生成和插槽兩個(gè)方式,主要把el-table 和el-pagination封裝在一起,結(jié)合示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08
Vue登錄主頁(yè)動(dòng)態(tài)背景短視頻制作
這篇文章主要為大家詳細(xì)介紹了Vue登錄主頁(yè)動(dòng)態(tài)背景短視頻的制作方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-09-09

