vue.js 购物车效果

购物车代码如下:

 <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content='width=device-width initial-scale=1.0, user-   scalable=no'>
<link rel="stylesheet" href="./bootstrap/css/bootstrap.css">
<title>shopping</title>
</head>
<body>
<div class="container">
    <table class="table table-bordered">
        <thead >
            <tr>
                <th class="text-center">编号</th>
                <th class="text-center">名称</th>
                <th class="text-center">单价</th>
                <th class="text-center">数量</th>
                <th class="text-center">总价</th>
            </tr>
        </thead>
        <tbody class="text-center">
            <tr v-for="(value,index) in arr">
                <td>{{index+1}}</td>
                <td>{{value.two}}</td>
                <td>{{value.three}}</td>
                <td><button v-on:click='list(index)'>+</button>
                <span>{{value.four}}</span>
                <button v-on:click='list1(index)'>-</button></td>
                <td>{{value.five}}</td>
            </tr>
            <tr>
                <td colspan="5" class="text-center">总计:{{arrs}}.00</td>
            </tr>
        </tbody>
    </table>
</div>
<script src="../vue.js"></script>
<script>
    new Vue({
        el:'.container',
        data:{
            arr:[
                {two:'香蕉',three:1,four:1,five:1},
                {two:'芒果',three:2,four:1,five:2},
                {two:'葡萄',three:3,four:1,five:3}
            ],
            arrs:6,
        },
         methods:{
                list:function(ind){
                   this.arr[ind].four++;
 //                     小计:
                  this.arr[ind].five=this.arr[ind].four*this.arr[ind].three;
//                     总计:
                    this.total();
                },
                list1:function(ind){
                   if(this.arr[ind].four>1){
                       this.arr[ind].four--;
                   }
 //                    小计:
                   this.arr[ind].five=this.arr[ind].four*this.arr[ind].three
//                       总计
                   this.total();
                },
             
//                    总计:
                total:function(){
                    for(var i=0,tot=0;i<this.arr.length;i++){
                        tot+=this.arr[i].five;
                    }
                    this.arrs=tot;
                }
            }
    })
    </script>
   </body>
</html>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 购物车实作思路: [TOC] 1.建立将商品加入到购物车的action (1)在商品页面新建“加入购物车”按钮(2...
    稻草人_b788阅读 2,104评论 3 5
  • 购物车是每个商城类的app必备的实现功能,然而购物车模块实现起来并不简单,需要考虑的地方也比较多,当初我实现起来也...
    爱猫的仙生阅读 7,852评论 1 26
  • 车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车车...
    凉的清水阅读 2,853评论 5 4
  • 三秦锁钥地, 五路襟喉关。 民族根始华夏, 始祖帝轩辕。 薪火相传千古。 更有红军接力, 灯塔亮延安。 抗日中流柱...
    果然全身阅读 728评论 24 18
  • 我一直觉得自己的人生在随着一条条冥冥之中的指引前进,我相信平行空间,相信缘分与命中注定。我总觉得自己很了解自己却又...
    张逸Rabbit阅读 283评论 0 0

友情链接更多精彩内容