Vue實(shí)現(xiàn)簡易購物車頁面
更新時(shí)間:2020年12月30日 10:09:03 作者:小王同學(xué)Max
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)簡易購物車頁面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
VUE實(shí)現(xiàn)簡易購物車效果,供大家參考,具體內(nèi)容如下
簡易的購物車小demo
引用了一下bootstrap3,的表格

<section id="gouwuche">
<table class="table table-hover">
<thead>
<tr>
<th>
<input type="checkbox" @change="handlechange" v-model="isAllChange" @click='inshow()'/>
全選
</th>
<th>商品信息</th>
<th>單價(jià)</th>
<th>數(shù)量</th>
<th>金額</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr style="height:50px;"></tr>
<tr v-for="(date,index) in arr" :class="{bgcolor:isActive}">
<td>
<input type="checkbox" v-model="checkgroup" :value="date" @change="handleLiChange" />
<img :src="date.imges"/>
{{date.name}}
</td>
<td>
<p>{{date.networkType}}</p>
<p>{{date.colorClass}}</p>
<p>{{date.packageType}}</p>
<p>{{date.rom}}</p>
<p>{{date.purchaseMethod}}</p>
<br>
</td>
<td>
<p><b class="danjia">{{date.price}}</b></p>
</td>
<td>
<button @click="handleDelclike(date)" >-</button>
<input type="text" :value="date.numbers"/>
<button @click="date.numbers++">+</button>
</td>
<td>
<p><b class="jiner">{{getSumje(date)}}.00</b></p>
</td>
<td>
<p>移入收藏夾</p>
<a href="#" @click="rmove(index)">刪除</a>
</td>
</tr>
</tbody>
</table>
<div class="box">
<div class="boxa">
<input type="checkbox" @change="handlechange" v-model="isAllChange" @click='inshow()'/>
<a href="#" >全選</a>
<a href="#" >刪除</a>
</div>
<div class="boxc">
<p>已選商品:<b class="jiner">{{checkgroup.length}}</b></p>
<p>合計(jì)(不含運(yùn)費(fèi)):<b class="jiner">{{getSum()}}<b></p>
</div>
<div class="boxb" >
結(jié)算
</div>
</div>
</section>
CSS:
#gouwuche {
width: 1200px;
height: ;
margin: 0 auto;
}
.box {
width: 1200px;
height: 50px;
margin: 30px auto;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #C4E3F3;
}
.boxa {
width: 780px;
height: 50px;
}
.boxa a {
margin-right: 50px;
}
.boxb {
width: 120px;
height: 50px;
background-color: #C0C0C0;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-size: 18px;
}
.boxc {
width: 300px;
height: 50px;
display: flex;
align-items: center;
justify-content: space-between;
}
input {
width: 50px;
text-align: center;
}
img {
width: 60px;
height: 60px;
}
a {
text-decoration: none;
color: #000;
}
* {
font-size: 12px;
}
p {
margin: 0;
padding: 0;
line-height: 1.9;
}
.danjia {
font-size: 16px;
}
.jiner {
font-size: 18px;
color: #FF8C00;
}
.bgcolor{
background-color: rgba(205,205,205,0.2);
}
js:
var gouwuche = new Vue({
el:"#gouwuche",
data:{
checkgroup:[],
isAllChage:false,
isActive:false,
arr:[
{
//商品名
name:"小米 note8 Pro",
//圖片地址
imges:"img/t1.jpg",
//顏色分類
colorClass:"機(jī)身顏色:冰翡翠",
//網(wǎng)絡(luò)類型
networkType:"網(wǎng)絡(luò)類型:4G+全網(wǎng)通",
//套餐類型
packageType:"套餐類型:官方標(biāo)配",
//存儲(chǔ)容量
rom:"存儲(chǔ)容量:6+128GB",
//購買方式
purchaseMethod:"官方旗艦店",
//單價(jià)
price:1299.00,
//數(shù)量
numbers:1,
//金額
money:1299.00,
//索引
id:"1",
},
{
//商品名
name:"紅米 k30 5G",
//圖片地址
imges:"img/t3.jpg",
//顏色分類
colorClass:"機(jī)身顏色:紫玉幻境",
//網(wǎng)絡(luò)類型
networkType:"網(wǎng)絡(luò)類型:5G+全網(wǎng)通",
//套餐類型
packageType:"套餐類型:官方標(biāo)配",
//存儲(chǔ)容量
rom:"存儲(chǔ)容量:8+128GB",
//購買方式
purchaseMethod:"官方旗艦店",
//單價(jià)
price:1499.00,
//數(shù)量
numbers:1,
//金額
money:1499.00,
//索引
id:"2",
},
{
//商品名
name:"紅米 k30 Pro",
//圖片地址
imges:"img/t4.jpg",
//顏色分類
colorClass:"機(jī)身顏色:象牙白",
//網(wǎng)絡(luò)類型
networkType:"網(wǎng)絡(luò)類型:5G+全網(wǎng)通",
//套餐類型
packageType:"套餐類型:官方標(biāo)配",
//存儲(chǔ)容量
rom:"存儲(chǔ)容量:8+256GB",
//購買方式
purchaseMethod:"官方旗艦店",
//單價(jià)
price:3999.00,
//數(shù)量
numbers:1,
//金額
money:3999.00,
//索引
id:"3",
},
{
//商品名
name:"紅米 k20 Pro",
//圖片地址
imges:"img/t4.jpg",
//顏色分類
colorClass:"機(jī)身顏色:象牙白",
//網(wǎng)絡(luò)類型
networkType:"網(wǎng)絡(luò)類型:5G+全網(wǎng)通",
//套餐類型
packageType:"套餐類型:官方標(biāo)配",
//存儲(chǔ)容量
rom:"存儲(chǔ)容量:8+256GB",
//購買方式
purchaseMethod:"官方旗艦店",
//單價(jià)
price:3999.00,
//數(shù)量
numbers:1,
//金額
money:3999.00,
//索引
id:"3",
}
],
},
methods:{
inshow:function(){
this.isActive = !this.isActive;
},
//總額
getSum:function(){
var sum = 0;
for(var i in this.checkgroup){
sum += this.checkgroup[i].numbers * this.checkgroup[i].price;
}
return sum;
},
//單品總額
getSumje:function(date){
var sum = date.price;
sum *= date.numbers;
return sum;
},
//判斷全選框
handlechange:function(){
if(this.isAllChange){
this.checkgroup = this.arr;
}else{
this.checkgroup = [];
}
},
//判斷全選框
handleLiChange:function(){
if(this.checkgroup.length !== this.arr.length){
this.isAllChange = false;
}else{
this.isAllChange = true;
}
},
//數(shù)量減1
handleDelclike:function(date){
var numbers = date.numbers--;
if(numbers === 1){
date.numbers = 1;
}
},
//刪除
rmove:function(index){
var that = this;
that.arr.splice(index,1);
that.checkgroup.splice(index,1);
}
}
})
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Vue實(shí)現(xiàn)購物車詳情頁面的方法
- 用vuex寫了一個(gè)購物車H5頁面的示例代碼
- vue之Element-Ui輸入框顯示與隱藏方式
- vue element-ui el-table組件自定義合計(jì)(summary-method)的坑
- Vue中安裝element-ui失敗問題原因及解決
- vue+element-ui前端使用print-js實(shí)現(xiàn)打印功能(可自定義樣式)
- Vue中使用element-ui給按鈕綁定一個(gè)單擊事件實(shí)現(xiàn)點(diǎn)擊按鈕就彈出dialog對(duì)話框
- vue2.x element-ui實(shí)現(xiàn)pc端購物車頁面demo
相關(guān)文章
解決vue組件沒顯示,沒起作用,沒報(bào)錯(cuò),但該顯示的組件沒顯示問題
這篇文章主要介紹了解決vue組件沒顯示,沒起作用,沒報(bào)錯(cuò),但該顯示的組件沒顯示問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-09-09
Vue+Element樹形表格實(shí)現(xiàn)拖拽排序示例
本文主要介紹了Vue+Element樹形表格實(shí)現(xiàn)拖拽排序示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08
vue-cli2,vue-cli3,vite?生產(chǎn)環(huán)境去掉console.log
console.log一般都是在開發(fā)環(huán)境下使用的,在生產(chǎn)環(huán)境下需要去除?,本文主要介紹了vue-cli2,vue-cli3,vite?生產(chǎn)環(huán)境去掉console.log,具有一定的參考價(jià)值,感興趣的可以了解一下2024-05-05
vue和iview結(jié)合動(dòng)態(tài)生成表單實(shí)例
這篇文章主要介紹了vue和iview結(jié)合動(dòng)態(tài)生成表單實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10

