• vue自学小demo----前端


    vue学习的小demo,实现简单的页面项目的增删

    代码如下

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>Vue</title>
        <script src="./vue.js"> </script>
        <link rel="stylesheet" href="./bootstrap.css">
    </head>
       <body>
           
          <div id="app" > 
             <dive class="panel panel-primary">
             <div class="panel-heading"> 
                 <h3 class="panel-title">添加品牌</h3>
             </div>
            <dive class="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="ok">
                    <label >
                            搜索:<input type="text"  class="form-control" v-model="keywords">
                        </label>
           
                <!-- form---inline 使得显示一行 -->
             </dive>
             </dive>
              <table class="table table-bordered table-hover table-striped">
                  <thead>
                      <tr>
                          <th>id</th>
                          <th>名字</th>
                          <th>ctime</th>
                          <th>opertation</th>
                          
                      </tr>
                  </thead>
                  <tbody>
                        <thead>
                                <tr v-for="item in serrch(keywords)" :key="item.id">
                                    <th>{{item.id}}</th>
                                    <th>{{item.name}}</th>
                                    <th>{{item.ctime}}</th>
                                    <th><a href="" @click.prevent="del(item.id)">删除 </a></th>
                                </tr>
                            </thead>
                  </tbody>
              </table>
          </div>
         
          <script>
             var vm = new Vue({
              
                el: '#app',
    
                data: {
                    id:'',
                    name:'',
                    keywords:'',
    
              list:[
                  {id:1,name:'奔驰',ctime:new Date()},
                  {id:2,name:'宝马',ctime:new Date()}
              ]  
                },
                methods: {
                    ok(){
                        // 2console.log("ok")
                        var add2={id:this.id,name:this.name,ctime: new Date() }
                        this.list.push(add2),
                        this.id=this.name=''
                    }, 
                       
                    del(id){ 
                        // this.list.some((item,i)=>{
                        //     if(item.id==id ){
                        //         this.list.splice(i,1)
                        //     }
                        // })
                        var i=this.list.length
                        var j=0
                        for(j=0;j<i;j++){
                            if(this.list[j].id==id){
                                this.list.splice(j,1)
                            }}},
                   serrch(keywords){
                       var newlist=[]
                       this.list.forEach(item=>{
                           if(item.name.indexOf(keywords)!=-1)  {
                         
                               newlist.push(item)
                           }
                       })
                       return newlist
                   }
                }
            });
          </script>
       </body>
    </html> 
  • 相关阅读:
    linux上安装mysql
    Linux上安装elasticsearch
    解决pyhton aiohttp ssl:None [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)
    mysql数据库的数据变更事件获取以及相关数据
    [天下小黑盒]打地鼠小助手
    看到当年自己学SQL Server 的笔记
    CodeFirst EF中导航属性的个人理解
    在Win10下如何安装IMSL6.0
    商品中台三期压测
    压测
  • 原文地址:https://www.cnblogs.com/Tqin/p/11741098.html
Copyright © 2020-2023  润新知