vue實(shí)現(xiàn)商品多選功能
本文實(shí)例為大家分享了vue實(shí)現(xiàn)商品多選功能的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html lang="en"> <head> ? <meta charset="UTF-8"> ? <meta name="viewport" content="width=device-width, initial-scale=1.0"> ? <meta http-equiv="X-UA-Compatible" content="ie=edge"> ? <title>vue實(shí)現(xiàn)實(shí)現(xiàn)全選,結(jié)算</title> </head> <style> ? ? *{ ? ? ? margin: 0; ? ? ? padding: 0; ? ? ? list-style: none; ? ? } ? #app{ ? ? width: 80%; ? ? margin: auto; ? } ? .wrap{ ? ? width: 100%; ? ? margin: auto; ? } ? .shangjia{ ? ? font-size: 20; ? ? font-weight: bold; ? ? color: #000; ? ? height: 36px; ? ? line-height: 36px; ? } ? .checked_inpu{ ? ? margin-right: 10px; ? ? margin-left: 10px; ? } ? .all_list{ ? ? padding-top: 10px; ? ? width: 100%; ? ? margin: auto; ? ? background: #bbb; ? } ?.list_item{ ? ?width: 80%; ? ?display: flex; ? ?justify-content: flex-start; ? ?position: relative; ? ?margin: 3px 0; ? ?padding: 6px 0; ?} ?img{ ? ?display: inline-block; ?} ?.list_box{ ? ?display: inline-block; ?} .list_img_tit_price{ ? display:inline-flex; ? align-content:space-between; } .list_img{ ? width: 100px; ? height: 100px; } .list_tit_price{ ? display: flex; ? flex-flow: column; ? margin-left:10px; ? font-size: 16px; ? justify-content: space-between; } .total{ ? display:inline-flex; ? flex-wrap: row; ? float: right; ? margin-top: 60px; ? margin-left: 20px; } .num_cancle, .num_add { ? ?font-size: 20px; ? ?font-weight: bolder; ? ?margin:0 2px; ? ?padding: 1PX; ? ?line-height: 36px; } .num_cancle:hover, .num_add:hover{ ? cursor: pointer; } .num_total{ ? width:30px; ? text-align: center; ? font-weight: bold; } .result{ ? float: right; ? display: inline-flex; } .heji{ ? margin: 0 12px; ? padding:3px; } .jisuan_btn{ ? color: #fff; ? background: #f30; ? font-size: 18px; ? font-weight: bold; ? padding: 3px; ? border-style: none; } </style> <body> ? <div id="app"> ? ? ?<div class="wrap shangjia"> ? ? ? ?<input type="checkbox" class="checked_inpu" v-model="checkedAll">選擇商家全部商品 ? ? ?</div> ? ? ?<div class="wrap all_list"> ? ? ? ?<ul> ? ? ? ? ?<li ? ? ? ? ? v-for="(item, index) in allList" ? ? ? ? ? class="list_item" > ? ? ? ? ? ?<input ? ? ? ? ? ? v-model="item.checked" ? ? ? ? ? ? type="checkbox"? ? ? ? ? ? ? class="checked_inpu"> ? ? ? ? ? ?<div class="list_box"> ? ? ? ? ? ? ?<div class="list_img_tit_price">? ? ? ? ? ? ? ? ? <img :src="item.src" alt="" class="list_img"> ? ? ? ? ? ? ? ? <div class="list_tit_price"> ? ? ? ? ? ? ? ? ? <div>{{item.title}}</div> ? ? ? ? ? ? ? ? ? <div style="color:red;">¥{{item.price}}</div> ? ? ? ? ? ? ? ? </div> ? ? ? ? ? ? ?</div> ? ? ? ? ? ? ?<div class="total"> ? ? ? ? ? ? ? ?<div class="num_cancle" @click="controlNum('cancle', index)">-</div> ? ? ? ? ? ? ? ?<input type="text" class="num_total" v-model.number="item.order"> ? ? ? ? ? ? ? ?<div class="num_add" @click="controlNum('add',index)">+</div> ? ? ? ? ? ? ?</div> ? ? ? ? ? ?</div> ? ? ? ? ?</li> ? ? ? ?</ul> ? ? ?</div> ? ? ?<div class="wrap"> ? ? ? ? <input type="checkbox" class="checked_inpu" v-model="checkedAll">全選 ? ? ? ? <div class="result"> ? ? ? ? ? <div class="heji">合計(jì):<span>{{amountPrice}}</span></div> ? ? ? ? ? <button class="jisuan_btn">去結(jié)算({{sumTotal}})</button> ? ? ? ? </div> ? ? ? </div> ? </div> </body> <script src="./vue.js"></script> <script> ? const vm = new Vue({ ? ? el:"#app", ? ? data:{ ? ? ? ?allList:[ ? ? ? ? ?{ ? ? ? ? ? ?title:"【第一】黃河之水天上來(lái),奔流到海不復(fù)回", ? ? ? ? ? ?src:'./img/1.jpg', ? ? ? ? ? ?price:880, ? ? ? ? ? ?order:1, ? ? ? ? ? ?id:0 ? ? ? ? ?}, ? ? ? ? ?{ ? ? ? ? ? ?title:"【第二】黃河之水天上來(lái),奔流到海不復(fù)回", ? ? ? ? ? ?src:'./img/2.jpg', ? ? ? ? ? ?price:881, ? ? ? ? ? ?order:1, ? ? ? ? ? ?id:1 ? ? ? ? ?}, ? ? ? ? ?{ ? ? ? ? ? ?title:"【第三】黃河之水天上來(lái),奔流到海不復(fù)回", ? ? ? ? ? ?src:'./img/3.jpg', ? ? ? ? ? ?price:882, ? ? ? ? ? ?order:1, ? ? ? ? ? ?id:2 ? ? ? ? ?}, ? ? ? ? ?{ ? ? ? ? ? ?title:"【第四】黃河之水天上來(lái),奔流到海不復(fù)回", ? ? ? ? ? ?src:'./img/4.jpg', ? ? ? ? ? ?price:883, ? ? ? ? ? ?order:1, ? ? ? ? ? ?id:3 ? ? ? ? ?}, ? ? ? ? ?{ ? ? ? ? ? ?title:"【第五】黃河之水天上來(lái),奔流到海不復(fù)回", ? ? ? ? ? ?src:'./img/5.jpg', ? ? ? ? ? ?price:884, ? ? ? ? ? ?order:1, ? ? ? ? ? ?id:4 ? ? ? ? ?}, ? ? ? ? ?{ ? ? ? ? ? ?title:"【第六】黃河之水天上來(lái),奔流到海不復(fù)回", ? ? ? ? ? ?src:'./img/6.jpg', ? ? ? ? ? ?price:885, ? ? ? ? ? ?order:1, ? ? ? ? ? ?id:5 ? ? ? ? ?}, ? ? ? ?] ? ? }, ? ? methods:{ ? ? ? controlNum(temp,index){ ? ? ? ? if(temp==="add"){ ? ? ? ? ? this.allList[index].order++; ? ? ? ? }else{ ? ? ? ? ? if(this.allList[index].order<=1){ ? ? ? ? ? ? alert("數(shù)量不能小于一了喲?。?) ? ? ? ? ? ? return ; ? ? ? ? ? } ? ? ? ? ? this.allList[index].order--; ? ? ? ? } ? ? ? } ? ? }, ? ? computed:{ ? ? ? selectTotal(){ ? ? ? ? return this.allList.filter(el => el.checked) ? ? ? }, ? ? ? amountPrice(){ ? ? ? ? ? let price = 0; ? ? ? ? ? this.selectTotal.forEach(el => { ? ? ? ? ? ? ?price +=el.price * el.order ? ? ? ? ? }) ? ? ? ? ? return price; ? ? ? }, ? ? ? sumTotal(){ ? ? ? ? let total=0; ? ? ? ? for(let i = 0; i < this.selectTotal.length; i ++){ ? ? ? ? ? total += this.selectTotal[i].order; ? ? ? ? } ? ? ? ? return total; ? ? ? }, ? ? ? checkedClick(e){ ? ? ? ? return e; ? ? ? }, ? ? ? checkedAll:{ ? ? ? ? get(){ ? ? ? ? ? return this.allList.every(el=>el.checked) ? ? ? ? }, ? ? ? ? set(val){ ? ? ? ? ? this.allList.forEach(el=>el.checked=val) ? ? ? ? } ? ? ? } ? ? } ? }) ? ?vm.allList.forEach(el => vm.$set(el, "checked", false)); </script> </html>
未全選
全選
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
深入理解vue.js中$watch的oldvalue與newValue
這篇文章主要給大家介紹了關(guān)于vue.js中$watch的oldvalue與newValue的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),并且介紹了關(guān)于watch的其他測(cè)試,對(duì)大家學(xué)習(xí)或者使用vue.js具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編來(lái)一起看看吧。2017-08-08基于Vue3實(shí)現(xiàn)一個(gè)簡(jiǎn)單的方位動(dòng)畫(huà)
這篇文章主要為大家詳細(xì)介紹了如何基于Vue3實(shí)現(xiàn)一個(gè)簡(jiǎn)單的方位動(dòng)畫(huà),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-02-02Vue終端取消vue、prettier警告warn問(wèn)題
這篇文章主要介紹了Vue終端取消vue、prettier警告warn問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10Vue?Token過(guò)期問(wèn)題的2種解決方案小結(jié)
在使用token進(jìn)行登錄的過(guò)程中,如果token過(guò)期了,需要重新輸入用戶名和密碼登錄,這種體驗(yàn)肯定是不好的,下面這篇文章主要給大家介紹了關(guān)于Vue?Token過(guò)期問(wèn)題的2種解決方案,需要的朋友可以參考下2023-02-02詳解vue移動(dòng)端項(xiàng)目的適配(以mint-ui為例)
這篇文章主要介紹了詳解vue移動(dòng)端項(xiàng)目的適配(以mint-ui為例),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08Vue瀏覽器緩存sessionStorage+localStorage+Cookie區(qū)別解析
這篇文章主要介紹了Vue瀏覽器緩存sessionStorage+localStorage+Cookie區(qū)別解析,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-09-09vue?iview?導(dǎo)航高亮動(dòng)態(tài)設(shè)置方式
這篇文章主要介紹了vue?iview?導(dǎo)航高亮動(dòng)態(tài)設(shè)置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-05-05淺談Vue3.0新版API之composition-api入坑指南
這篇文章主要介紹了Vue3.0新版API之composition-api入坑指南,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04