使用vue制作一个简单的购物车

 以下便是html  和  js代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="index.css">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <!-- 最大的盒子 -->
        <div class="boss">
            <!-- 最上边的盒子 -->
            <div class="gouwuche">
                <div class="fangzi"><img src="家房子建筑.png"></div>
                <div class="a">/</div>
                <div class="gwc">购物车</div>
            </div>
            <table border="1" class="biaodan" cellspacing="0" cellpadding="0" width="100%" height="100px">
                <tr style="background-color: rgba(0, 0, 0, 0.1);height: 60px;">
                    <th>选中</th>
                    <th>图片</th>
                    <th>单价</th>
                    <th>个数</th>
                    <th>小计</th>
                    <th>操作</th>
                </tr>
                <!-- 第一行表格 -->
                <tr class="yinyingone" :class="{boxxx:biaoge==true}"  v-show="shanchuone" style="height: 100px; ">
                    <td > <input  v-model="biaoge" style="width: 30px;height: 30px;position: absolute;left: 30px;top: 160px;" type="checkbox"> </td>
                    <td><div class="tupian"><img src="家房子建筑.png"></div></td>
                    <td style="text-align: center;font-size: 30px;">20</td>
                    <td style="font-size: 30px;text-align: center;">
                        <button @click="func()" :disabled="number<=1" style="width: 50px;height: 50px;font-size: 30px;text-align: center;line-height: 50px;">-</button>
                        {{number}}
                        <button @click="func1()" style="width: 50px;height: 50px;font-size: 30px;text-align: center;line-height: 50px;">+</button>
                    </td>
                    <td>
                        <!-- 总和 -->
                         <input type="" value="" v-show="yincang"  v-model="zh">
                         <label for="" style="font-size: 30px;text-align: center;">{{sum}}</label>
                    </td>
                    <td><div class="shanchu" @click="shanchu()">删除</div></td>
                </tr>
                 <!-- 第二行表格 -->
                 <tr v-show="shanchutwo" :class="{boxxx:biaoge1==true}"  style="height: 100px;">
                    <td > <input  v-model="biaoge1" style="width: 30px;height: 30px;margin-left: -20px;top: 120px;" type="checkbox"> </td>
                    <td><div class="tupian"><img src="家房子建筑.png"></div></td>
                    <td style="text-align: center;font-size: 30px;">40</td>
                    <td style="font-size: 30px;text-align: center;">
                        <button @click="func2()" :disabled="number1<=1" style="width: 50px;height: 50px;font-size: 30px;text-align: center;line-height: 50px;">-</button>
                        {{number1}}
                        <button @click="func3()" style="width: 50px;height: 50px;font-size: 30px;text-align: center;line-height: 50px;">+</button>
                    </td>
                    <td>
                        <input type="" value="" v-show="yincang1"  v-model="zh1">
                        <label for="" style="font-size: 30px;text-align: center;">{{sum1}}</label>
                    </td>
                    <td><div class="shanchu" @click="shanchu1()">删除</div></td>
                </tr>
                 <!-- 第三行表格 -->
                 <tr class="yinyingthree" :class="{boxxx:biaoge2==true}" v-show="shanchuthree" style="height: 100px;">
                    <td > <input  v-model="biaoge2" style="width: 30px;height: 30px;margin-left: -20px;top: 120px;" type="checkbox"> </td>
                    <td><div class="tupian"><img src="家房子建筑.png"></div></td>
                    <td style="text-align: center;font-size: 30px;">3</td>
                    <td style="font-size: 30px;text-align: center;">
                        <button @click="func4()" :disabled="number2<=1" style="width: 50px;height: 50px;font-size: 30px;text-align: center;line-height: 50px;">-</button>
                        {{number2}}
                        <button @click="func5()" style="width: 50px;height: 50px;font-size: 30px;text-align: center;line-height: 50px;">+</button>
                    </td>
                    <td>
                        <input type="" value="" v-show="yincang2"  v-model="zh2" >
                        <label for="" style="font-size: 30px;text-align: center;height: 100px;">{{sum2}}</label>
                    </td>
                    <td><div class="shanchu" @click="shanchu2()">删除</div></td>
                </tr>
                 <!-- 第四行表格 -->
                 <tr  class="yinyingfour" :class="{boxxx:biaoge3==true}" style="height: 100px;">
                    <td > <input v-model="biaoge3" style="width: 30px;height: 30px;margin-left: -25px;top: 465px;position: absolute;" type="checkbox"> </td>
                    <td><div class="tupian"><img src="家房子建筑.png"></div></td>
                    <td style="text-align: center;font-size: 30px;">34</td>
                    <td style="font-size: 30px;text-align: center;">
                        <button @click="func6()" :disabled="number3<=1" style="width: 50px;height: 50px;font-size: 30px;text-align: center;line-height: 50px;">-</button>
                        <span style="text-align: center;">{{number3}}</span>
                        <button @click="func7()" style="width: 50px;height: 50px;font-size: 30px;text-align: center;line-height: 50px;">+</button>
                    </td>
                    <td>
                        <input type="" value="" v-show="yincang3" v-model="zh3">
                        <label for="" style="font-size: 30px;text-align: center;text-align: center;">{{sum3}}</label>
                    </td>
                    <td><div class="shanchu" @click="shanchu3()">删除</div></td>
                </tr>
            </table>
            <!-- 第二个盒子 -->
            <div class="twobox">
                <input v-model="quanxuan" @click="quanxuanbiaodan()" style="width: 50px;height: 50px; position: absolute;left: 20px; margin-top: 20px;" type="checkbox">
                <span class="quanxuan">全选</span>
                <button style="width: 200px;height: 50px;margin-left: 300px;margin-top: 20px;text-align: center;font-size: 30px;" @click="quanbuquxiao()">全部取消</button>
                <div class="zongjie">总价:  ¥</div>
                <div class="zonghe">{{numbersum}}</div>
                <div class="jiesuan">结算 ( {{jiesuan1}} )</div>
            </div>
        </div>
    </div>
</body>
<script src="../vue.js"></script>
<script>
    Vue.config.productionTip=false
    var vm=new Vue({
        el:"#app",
        data(){
            return{
                // 设置第一个表单个数为---7
                number:7,
                // 设置第一个表单个数为---3
                number1:3,
                // 设置第一个表单个数为---10
                number2:10,
                // 设置第一个表单个数为---20
                number3:20,
                biaoge:false,
                biaoge1:false,
                biaoge2:true,
                biaoge3:true,
                quanxuan:false,
                // numbersum:0,
                zh:140,
                zh1:120,
                zh2:30,
                zh3:680,
                // 隐藏表格一
                yincang:false,
                // 隐藏表格二
                yincang1:false,
                // 隐藏表格三
                yincang2:false,
                // 隐藏表格四
                yincang3:false,
                arr:[],
                // 点击删除按钮   删除第一个表格
                shanchuone:true,
                // 点击删除按钮   删除第二个表格
                shanchutwo:true,
                // 点击删除按钮   删除第三个表格
                shanchuthree:true,
                // 点击删除按钮   删除第四个表格
                shanchufour:true,
                // 总结算数量
                jiesuan1:30, 
                arr:[],
            }
        },
        computed:{
            // 第一个表格计算合计功能
            sum(){
                return (this.number)*20
            },
             // 第二个表格计算合计功能
            sum1(){
                return (this.number1)*40
            },
             // 第三个表格计算合计功能
            sum2(){
                return (this.number2)*3
            },
             // 第四个表格计算合计功能
            sum3(){
                return (this.number3)*34
            },
            // 总价求和功能
            numbersum(){
                return this.zh2+this.zh3;
            }
        },
        methods:{
            // 第一个表格减法功能
            func(){
                this.number--
            },
            // 第一个表格加法功能
            func1(){
                this.number++
            },
            // 第二个表格减法功能
             func2(){
                this.number1--
            },
            // 第二个表格加法功能
            func3(){
                this.number1++
            },
             // 第三个表格减法功能
            func4(){
                this.number2--
            },
            // 第三个表格加法功能
            func5(){
                this.number2++
            },
            // 第四个表格减法功能
            func6(){
                this.number3--
            },
            // 第四个表格加法功能
            func7(){
                this.number3++
            },
            // 点击全部选取表单
            quanxuanbiaodan(){
                this.biaoge=true;
                this.biaoge1=true;
                this.biaoge2=true;
                this.biaoge3=true;
            },
            // 点击全部取消表单
            quanbuquxiao(){
                this.biaoge=false;
                this.biaoge1=false;
                this.biaoge2=false;
                this.biaoge3=false;
                this.quanxuan=false
            },
            // 删除表格一
            shanchu(){
                this.shanchuone=false
            },
            // 删除表格二
            shanchu1(){
                this.shanchutwo=false
            },
            // 删除表格三
            shanchu2(){
                this.shanchuthree=false
            },
            // 删除表格四
            shanchu3(){
                this.shanchufour=false
            },
        }
    })
</script>
</html>

css部分

*{
    margin: 0;
    padding: 0;
}
.boss{
    width: 100%;
    height: 1000px;
    /* border: 1px solid black; */
    background: linear-gradient(aquamarine,pink);
}
.gouwuche{
    width: 115px;
    height: 30px;
    margin: 20px 20px;
    /* background-color: aqua; */
}
.fangzi{
    width: 30px;
    height: 30px;
    float: left;

}
.fangzi img{
    width: 100%;
    height: 100%;
    background-size: 5px 10px; 
 }  
 .a{
    float: left;
    font-size: 20px;
    line-height: 30px;
    margin-left: 5px;
 }
.gwc{
    font-size: 20px;
    line-height: 30px;
    margin-left: 5px;
}
 .biaodan{ 
    text-align: center;
    margin: 0 auto;
 } 
.tupian{
    width: 150px;
    height: 80px;
    margin: 0 auto;
}
.tupian img{
    width: 100%;
    height: 100%;
}
.shanchu{
    width: 100px;
    height: 50px;
    font-size: 30px;
    color: white;
    background-color: red;
    margin: 0 auto;
    text-align: center;
    line-height: 50px;
    cursor: pointer;
}
.shanchu:hover{
    color: aqua;
}
.twobox{
    width: 100%;
    height: 100px;
    /* background-color: pink; */
}
.quanxuan{
    font-size: 30px;
    text-align: center;
    /* line-height: 50px; */
    margin-top: 20px;
    margin-left: 80px;
    position: absolute;
}
.zongjie{
    font-size: 20px;
    /* float: right; */
    margin-left: 1300px;
    margin-top: -30px;
}
.jiesuan{
    width: 150px;
    height: 60px;
    color: white;
    font-size: 20px;
    text-align: center;
    line-height: 60px;
    margin-left: 1500px;
    margin-top: -55px;
    background-color: blue;
    cursor: pointer;
}
.zonghe{
    color: #9c27b096;
    font-size: 30px;
    margin-left: 1400px;
    margin-top: -35px;
    font-weight: bold;
}
.boxxx{
    background-color: rgba(0, 0, 0, 0.1) ;
}

 以下便是显示的效果

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值