购物车

作者: 天赐很棒 | 来源:发表于2018-09-21 15:13 被阅读0次
<!DOCTYPE html>

<html lang="en">

        <head>

<meta charset="UTF-8">

<title>Document</title>

<link rel="stylesheet" href="css/bootstrap.css">

 </head>

 <body>

<div class="container">

    <table class="table table-bordered text-center">

        <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>

            <tr v-for='(value,index) in lhf'>

                <td>{{index+1}}</td>

                <td>{{value.name}}</td>

                <td>{{value.price}}</td>

                <td>

                <button @click="lgy(index)">+</button>

                <span>{{value.count}}</span>

                <button @click="lbx(index)">-</button>

                </td>

                <td>{{value.count*value.price}}</td>

            </tr>

            <tr>

                <td colspan="5" class="text-center">总计:{{total}}</td>

            </tr>

        </tbody>

    </table>

</div>

js部分:

<script src="js/vue.js"></script>

<script>

    new Vue({

        el:'.container',

        data:{

            lhf:[

                {name:'bannana',price:'3',count:'3',sub:'9'},

                {name:'apple',price:'4',count:'4',sub:'16'},

                {name:'pear',price:'5',count:'5',sub:'25'}

            ],

            total:0

        },

        methods:{

            lgy:function(index){

            this.lhf[index].count++,

            this.lhf[index].sub=(this.lhf[index].price*this.lhf[index].count).toFixed(2)

            this.getTotal()

        },

            lbx:function(index){

            if(this.lhf[index].count>1){

            this.lhf[index].count--,

            this.lhf[index].sub=(this.lhf[index].price*this.lhf[index].count).toFixed(2)

        }

            this.getTotal()

        },

        getTotal:function(){

            var len=this.lhf.length

            var sum= 0;

            for(var i=0;i<len;i++){

                sum+=Number(this.lhf[i].sub)

            }

            this.total=sum.toFixed(2);

        }

    }

})

</script>

 </body>

 </html>                                           
6.png

相关文章

  • 商城之购物车

    购物车管理: 包含功能:提交商品到购物车、显示购物车列表、删除购物车里商品、修改购物车、清空购物车等等 1、购...

  • 购物车模块实现

    1、购物车列表功能实现 点击加入购物车或者点击购物车图标后进入购物车页面,在购物车页面中首先渲染cartList的...

  • SSM框架学习日记(6)——购物车模块

    购物车相关接口 添加购物车,购物车列表,更新商品数量,删除购物车先新建CartController和CartSer...

  • 8.5-高并发下的互联网电商购物车实战-加入购物车接口开发—小滴

    高并发下的互联网电商购物车实战-加入购物车接口开发 简介:电商购物车实现案例-加入购物车接口开发 添加购物车接口 ...

  • day11购物车10-细节完善

    购物车01-搭建基本骨架购物车02-圆角按钮处理购物车03-显示数据购物车04-加号减号点击处理购物车05-通知的...

  • day11购物车08-代理的简单实现

    购物车01-搭建基本骨架购物车02-圆角按钮处理购物车03-显示数据购物车04-加号减号点击处理购物车05-通知的...

  • day11-购物车06-清空和购买

    购物车01-搭建基本骨架购物车02-圆角按钮处理购物车03-显示数据购物车04-加号减号点击处理购物车05-通知的...

  • day11购物车07-KVO的应用

    购物车01-搭建基本骨架购物车02-圆角按钮处理购物车03-显示数据购物车04-加号减号点击处理购物车05-通知的...

  • day11购物车09-代理设计模式

    购物车01-搭建基本骨架购物车02-圆角按钮处理购物车03-显示数据购物车04-加号减号点击处理购物车05-通知的...

  • 8.购物车管理

    购物车管理模块是属于用户侧模块,主要有7个接口:添加商品到购物车、更新购物车商品数、移除购物车商品、查看购物车当中...

网友评论

      本文标题:购物车

      本文链接:https://www.haomeiwen.com/subject/vkemnftx.html