首页 > 其他分享 >前端___Vue小案例

前端___Vue小案例

时间:2022-12-27 19:34:22浏览次数:39  
标签:Vue name price id Date new ___ 前端

Vue小案例

  1. 包含bootstrap和Vue的使用
  2. 文本输入框,复选框与Vue变量的绑定
  3. 包含v-model,@,:,v-for,computed,methods,等语法的使用...
  4. 仅供复习时使用

源码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>library</title>
    <!-- <link rel="stylesheet" href="./bootstrap-3.4.1/dist/css/bootstrap.css"> -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
</head>
<body>

    <div class="app">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h2>图书管理系统</h2>
            </div>
            <div class="panel-body form-inline">
                <label >id:<input type="text" class="form-control"  v-model="id" ></label>
                <label >图书名称:<input type="text" class="form-control" v-model="name" ></label>
                <label >图书价钱:<input type="text" class="form-control" v-model="price" ></label>
                <input type="button" value="添加" class="btn btn-primary" @click="add">
            </div>
        
        <table  class="table table-bordered table-hover">
            <thead>
                <tr>
                    <th>id</th>
                    <th>图书名称</th>
                    <th>价钱</th>
                    <th>添加时间</th> 
                    <th>购买</th>
                    <th>操作</th>
                   
                </tr>
            </thead>
            <tbody>
                <tr v-for="item in arr" :key="item.id">
                <td v-text="item.id"></td>
                <td v-text="item.name"></td>
                <td v-text="item.price"></td>
                <td v-text="item.time"></td>
                <td>
                    <input type="checkbox"  :value=item.price v-model="selectedBooks">
                </td>
                 <td><a href="" @click.prevent="del(item.id)">删除</a></td> 
                 </tr>
            </tbody>
        </table>
        <div align="center" class="panel-heading">
            <h1>总价:{{cost}}</h1>
            <input type="button" value="购买" class="btn btn-success" @click="buy">
        </div>
    </div>
    </div>

    <script>
        
        var vm =new Vue({
            el:'.app',
            
            data:{
                arr:[
                    {id:1,name:'三国演义',price:45,time:new Date()},
                    {id:2,name:'水浒传',price:78,time:new Date()},
                    {id:3,name:'红楼梦',price:60,time:new Date()},
                    {id:4,name:'西游记',price:39,time:new Date()},
                    {id:5,name:'3D游戏开发',price:59,time:new Date()},
                ],
                selectedBooks:[],
                id:'',
                name:'',
                price:'',
            },
            computed:{
                cost(){
                    let t=0;
                    this.selectedBooks.forEach(element => {
                        t+=parseInt(element);
                       console.log(element);
                    });
                     return t;
                }
            }
            ,
            methods:{
                add(){
                    this.arr.push({
                        id:this.id,
                        name:this.name,
                        price:this.price,
                        time:new Date()
                    })
                    this.id=this.name=this.price='';
                },
                del(id){
                    var index=this.arr.findIndex(item=>{
                        if(item.id==id)return true;
                    })
                    this.arr.splice(index,1);
                },
                buy(){
                    alert("购买成功,共消费:"+this.cost);
                }
            }
        });
    </script>
</body>
</html>

标签:Vue,name,price,id,Date,new,___,前端
From: https://www.cnblogs.com/lxp-blog/p/17008813.html

相关文章

  • 微信公众平台网页授权两次重定向跳转问题
    在做微信公众平台网页授权时,发现每次请求授权链接​​https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxx&redirect_uri=xxx&response_type=code&scope=snsapi......
  • hdu: What Are You Talking About(map应用)
    ProblemDescriptionIgnatiusissoluckythathemetaMartianyesterday.Buthedidn’tknowthelanguagetheMartiansuse.TheMartiangiveshimahistoryb......
  • Selenium36-失败截图
    失败截图目标:断言失败时,截取当前被测系统界面图片,保存下来,以备后续分析问题时来使用。failureException变量:unittest框架里定义一个TestCase类里的固定名称的成员变量,代......
  • Unity中查找子组件GameObject或Component的操作汇总
    1.GameObject属性:tag常用于区分游戏中不同类型的对象(例如区分玩家和NPC)name:游戏物体的名称 方法:SetActive:使游戏物体处于活跃/不活跃状态例:other.gameObject.SetAc......
  • 实验5
    #define_CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<string.h>#defineN5typedefstructstudent{charname[10];intnum;intmaths;......
  • Unity3D学习之路
    1.准备C#的开发环境VS2015, Unity3D5.5.12.准备通信协议protobuf3.3.0 具体请参考:​​Protobuf3.3使用总结​​3.引入日志系统:​​C#日志系统Log4net使用总结​......
  • Lambda表达式
    Lambda表达式Lambda概述Lambda表达式时JDK8开始后的一种新语法格式作用:简化匿名内部类的代码写法Lambda表达式的简化格式注意:Lambda表达式只能简化函数式接口的匿......
  • 数据库连接池Druid使用总结
    根据综合性能,可靠性,稳定性,扩展性,易用性等因素替换成最优的​​数据库​​连接池。Druid:druid-1.0.29数据库 Mysql.5.6.17替换目标:替换掉C3P0,用druid来替换替换原因:1、......
  • 日志切面
    @Aspect@ComponentpublicfinalclassLogAspect{privatestaticfinalLoggerLOGGER=LoggerFactory.getLogger(LogAspect.class);/***线程本......
  • Logback日志框架
    日志框架日志技术的概述生活中的日志:生活中的日志就好比日记,可以记录生活的点点滴滴程序中的日志:程序中的日志可以用来记录程序运行过程中的信息,并可以进行永久储存......