vue自学小demo----前端

摘要:
vue学习的小演示实现了以下用于添加或删除简单页面项的代码:!DOCTYPE html˃Vue添加品牌id:名称:搜索:˂!

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

vue自学小demo----前端第1张

代码如下

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

免责声明:文章转载自《vue自学小demo----前端》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇将本地jar包手动复制到Maven库中,在其它电脑上用Maven打包时出错TP6框架--EasyAdmin学习笔记:实现数据库增删查改下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Python map 函数 -Python零基础入门教程

目录 一.前言 二.Python map 函数语法简介 三.Python map 函数实战 1.使用 map 函数 2.map 函数配合 lambda 匿名函数一起使用 四.Python map 函数效率对比 五.Python map 函数总结 六.猜你喜欢 零基础 Python 学习路线推荐 : Python 学习目录 >> Pyt...

vue el-table 自适应表格内容宽度

由于表头和列是分开渲染的,通过el-table 设置fit属性,只能撑开表头,但是没有办法根据列的内容去适应宽度。网上找了一些使用根据表格内容计算表头宽度的文章,记个笔记。 代码逻辑是通过vue 的watch 监控表格的数据data,计算每列的内容和表头的最大宽度,计算的时候把表格内容使用span标签包裹,然后计算span标签的宽度width:px,然后再...

vue路径别名无法识别,Cannot find module

编辑器:vscode; 技术:vue-cli4,ts; 例子:import { login } from "@api/user"; 问题:Cannot find module '@/*'.Vetur(2307); 此种情况无法找到模块也不能点击,但是编译后是可以使用的。 原因:无法解析别名模块。 解决方法: 将项目放到vscode工作区根目录(只留一个项目...

React == 实现简易购物车

React == 实现简易版购物车 1、几个要点: 为了方便后面使用input type = "checkbox" 实现复选框的选中/不选中,给传递过来的属性要在遍历的时候,单独加上一个新属性 checked count 属性 默认值 都是1. state = { all : false, sumprice :0, one...

vue 图片上传功能

  这次做了vue页面的图片上传功能,不带裁剪功能的! 首先是html代码,在input框上添加change事件,如下:   <ul class="clearfix">   <li v-if="imgs.length>0" v-for='(item ,index ) in imgs'>   <img :...

vue 获取元素高度

1、html <div ref="getheight"></div> <br><br> 2、JavaScript //获取高度值 (内容高+padding+边框) let height= this.$refs.getheight.offsetHeight; //获取元素样式值 (存在单位) le...