zoukankan      html  css  js  c++  java
  • 汽车系统实现--增加数据和删除数据

    
    
    <div id="app">
    <div class="panel panel-primary">
    <div class="panel-heading">
    <h3 class="panel-title">添加品牌</h3>
    </div>
    <div class="panel panel-body form-inline">
    <label>
    Id:<input type="text" class="form-control" v-model="id">
    </label>

    <label>
    name:<input type="text" class="form-control" v-model="name">
    </label>

    <input type="button" value="添加" class="btn btn-primary" @click="add">
    </div>
    </div>


    <table class="table table-striped">
    <thead>
    <tr>
    <th>Id</th>
    <th>Name</th>
    <th>Ctime</th>
    <th>Operation</th>
    </tr>
    </thead>

    <tbody>
    <tr v-for="item in list" :key="item.id">
    <td>{{ item.id }}</td>
    <td>{{ item.name }}</td>
    <td>{{ item.ctime }}</td>
    <td><a href="#" @click.prevent="del(item.id)">删除</a></td>
    </tr>
    </tbody>
    </table>
    </div>
     
     1 <script>
     2 var vm=new Vue({
     3     el:"#app",
     4     data:{
     5         id:'',
     6         name:'',
     7         list:[
     8             {id:1,name:"宝马",ctime:new Date()},
     9             {id:2,name:"奔驰",ctime:new Date()},
    10     ]
    11     },
    12     methods: {
    13         add(){ //添加的方法 
    14          var car={ id:this.id,   name:this.name, ctime:new Date()}
    15         
    16          this.list.push(car);
    17 
    18         //  当你输入后可以清空。不让他在此占位
    19         //  this.id='';
    20         //  this.name='';
    21         this.id=this.name='';
    22         },
    23         del(id){
    24             // 如何根据id,删除该索引中的数据哦,---第一种方式
    25             //  this.list.some((item,i)=>{
    26             //      if(item.id==id){
    27             //          console.log(id)
    28             //          this.list.splice(i,1)
    29             //         //  在数组中some方法,如果return true,就会立刻终止这个数组的后续循环。
    30             //          return true;
    31             //      }
    32             //  })
    33             // 找到索引直接。直接调用数组的splice这个方法
    34 
    35 
    36             // 快速的找到索引值----第而只能够放似
    37             var index=this.list.findIndex(item=>{
    38                 if(item.id==id){
    39                     return true;
    40                 }
    41             });
    42             // console.log(index);
    43             this.list.splice(index,1);
    44 
    45         }
    46     },
    47 
    48 })
    49 </script>
  • 相关阅读:
    java8 stream().map().collect()用法
    Java中Collections的emptyList、EMPTY_LIST详解
    zxing实现java二维码生成和解析
    机器学习与数据挖掘—K邻近算法(KNN)
    第一个Web项目(IDEA)
    Ucore操作系统实验-实验课程设计
    数据挖掘与机器学习--损失函数
    机器数据挖掘--常见监督学习算法以及数据挖掘流程
    Tomcat安装-环境变量配置-启动-关闭
    操作系统实验教程(Ucore)--Lab6
  • 原文地址:https://www.cnblogs.com/IwishIcould/p/10872879.html
Copyright © 2011-2022 走看看