美文网首页
2018-09-17 作业:用户管理页面 购物车 选项卡

2018-09-17 作业:用户管理页面 购物车 选项卡

作者: 好多好多鱼z | 来源:发表于2018-09-17 11:18 被阅读0次

购物车

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</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 arr">
            <td>{{index+1}}</td>
            <td>{{value.name}}</td>
            <td>{{value.price}}</td>
            <td>
                <button @click="add(index)">+</button>
               <span>{{value.num}}</span>
                <button @click="jian(index)">-</button>
            </td>
            <td>{{value.sub}}</td>
        </tr>
        <tr >
            <td colspan="5" text-center>总价:{{sum}}</td>
        </tr>
        </tbody>
    </table>

</div>
<script src="js/vue.js"></script>
<script>
    new Vue({
        el:".container",
        data:{
            arr:[
                {name:"香蕉",price:2,num:3,sub:6},
                {name:"香蕉",price:2,num:3,sub:6},
                {name:"香蕉",price:2,num:3,sub:6}
            ],
            sum:18
        },
        methods:{
            add:function(i){
                this.arr[i].num++;
                this.arr[i].sub=this.arr[i].price*this.arr[i].num;
                this.a();
            },
            jian:function(i){
                if(this.arr[i].num>1){
                    this.arr[i].num--;
                    this.arr[i].sub=this.arr[i].price*this.arr[i].num;
                }
                this.a();
            },
            a:function(){
                for(var i=0,p=0;i<this.arr.length;i++){
                    p+=this.arr[i].sub
                }
                this.sum=p
            }

        }
    })
</script>
</body>
</html>
1.png

用户管理页面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/bootstrap.css">
</head>
<body>
<div class="container">
    <form>
        <div class="form-group">
            <label>名字</label>
            <input placeholder="请输入名字"  class="form-control" v-model="arrs.name">
        </div>
       <div class="form-group">
           <label>年龄</label>
           <input placeholder="请输入年龄"  class="form-control"  v-model="arrs.age">
       </div>
        <div class="form-group">
            <label>邮箱</label>
            <input placeholder="请输入邮箱"  class="form-control"  v-model="arrs.email">
        </div>
        <div class="form-group text-center">
            <input type="button" value="添加" class="btn btn-success" @click="add">
            <input type="button" value="重置" class="btn btn-info">
        </div>
    </form>
    <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 arr">
            <td>{{index+1}}</td>
            <td>{{value.name}}</td>
            <td>{{value.age}}</td>
            <td>{{value.email}}</td>
            <td>
                <button @click="splice(index)">删除</button>
            </td>

        </tr>
        </tbody>
    </table>
</div>
<script src="js/vue.js"></script>
<script>
    new Vue({
        el:".container",
        data:{
            arr:[
                {name:"jack",age:18,email:"123@126.com"},
                {name:"jack",age:18,email:"123@126.com"},
                {name:"jack",age:18,email:"123@126.com"}
            ],
            arrs:{name:"",age:"",email:""}
        },
        methods:{
            add:function(){
               this.arr.push(this.arrs),
                this.arrs={}
            },
            splice:function(index){
                this.arr.splice(index,1)
            }
        }
    })
</script>
</body>
</html>
2.png

选项卡

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    <ul>
        <li v-for="(value,index) in card" @click="p(index)">{{value.title}}</li>
    </ul>
    <ul>
        <li v-for="(value,index) in card" v-show="value.flag">{{value.content}}</li>
    </ul>

</div>
<script src="js/vue.js"></script>
<script>
    new Vue({
        el:"#app",
        data: {
            card: [
                {title: "选项卡1", content: "xuanxiangka",flag:true},
                {title: "选项卡2", content: "xuanxiangka2",flag:false},
                {title: "选项卡3", content: "xuanxiangka3",flag:false}
            ]
        },
        methods:{
            p:function(ind){
                for(var i=0;i<this.card.length;i++){
                    this.card[i].flag=false;
                }
                this.card[ind].flag=true;
            }

        }
    })
</script>
</body>
</html>

相关文章

  • 2018-09-17 作业:用户管理页面 购物车 选项卡

    购物车 用户管理页面 选项卡

  • 与Vue.js的第四天

    课堂作业 用户管理 结构是bootstrap搭建 购物车 选项卡

  • vue指令应用

    应用1: 购物车 代码如下: 应用2: 选项卡 代码如下: 应用3: 用户管理 代码如下:

  • Vue笔记 添加用户,选项卡,购物车加减

    购物车加减效果: 选项卡效果: 添加用户效果:

  • 购物车刷新策略

    APP主页 前言 电商APP基本都有购物车页面,购物车的数据会受用户在其他页面的操作的影响。比如说:用户不仅可以在...

  • 四 jq购物车

    1 购物车,其实就是把用户选择商品的关键信息在详情页(或含有加入购物车的页面)储存起来,拿到购物车页面展示,对,就...

  • 2019-08-01 PHP+MySQL开发简单的留言板(4)

    现在我们需要开发后台管理页面和与之对应的删除留言、用户的功能。 后台管理页面的开发 后台管理页面需要显示所有的用户...

  • 关于 onbeforeunload

    页面在关闭前会有onbeforeUnload事件,来询问用户是否要关闭这个页面OR选项卡 浏览器的F5刷新为按下F...

  • MVC(页面跳转)

    产品列表页面 "加入购物车" "查看详情" 产品详情页面 "返回列表" "加入购物车" 购物车页面 "继续购物"

  • JS第一部分 8.17

    一、js简介 1.JavaScript用来制作web页面交互效果,提升用户体验。(表单验证、选项卡、轮播图、地图)...

网友评论

      本文标题:2018-09-17 作业:用户管理页面 购物车 选项卡

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