vue.js如何实现购物车加减操作

vue.js如何实现购物车加减操作


效果图

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="css/css.css">
    <script src="js/vue.js"></script>
    <title>Vue</title>
</head>

<body>
    <div id="app">
        <div class="hd">
            <span>
                <input type="checkbox" id="selectAll" v-model="cheackValue" />
                <label for="selectAll">全选</label>
            </span>
            <span>商品名称</span>
            <span>单价</span>
            <span>数量</span>
            <span>小计</span>
            <span>操作</span>
        </div>
        <div class="goods-list">
            <div class="check-btn"><input type="checkbox"></div>
            <div class="goods-img"><img src="img/canon.jpg" alt=""></div>
            <div class="goods-name"><em>AOC 23英寸IPS显示器</em></div>
            <div class="goods-price"><em>¥150.00</em></div>
            <div class="goods-quantity">

                <button v-on:click="subtract()">-</button>
                <input type="text" value="0" v-model="count">
                <button v-on:click="add()">+</button>

            </div>
            <div class="goods-subtotal"><em>¥0.00</em></div>
            <div class="goods-operate"><a href="javascript:void(0)">删除</a></div>
        </div>
        <div class="clearing">
            <span><a href="javascript:void(0)">删除选中的商品</a></span>
            <span>已选择<em>1</em>件商品</span>
            <span>总价:¥<em>0.00</em></span>
            <span><a href="#">去结算</a></span>
        </div>
    </div>
</body>

</html>
<script>
        var vm = new Vue({
            el: "#app",
            data: {
                count: 0
            },
            methods: {
            //实现数字增加
                add: function(count) {
                    this.count++;
                },
                //数字减少,如果少于0则弹出不能再少
                subtract: function(count) {
                    if (this.count <= 0) {
                        alert("不能少了")
                    } else {
                        this.count -= 1;

                    }
                }

            }
        });

    </script>
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值