• vue.js实现添加删除


    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>图书馆增加书</title> 
      <script src="js/vue.js"></script>
      <style>
        ul{
          list-style: none;
          100px;
          height:auto;
        }
       
        .buttonstylelist{
          80px;
          height:30px;
          border:1px solid blue;
          color:#fff;
          background: blue;
        }
      </style>
    </head>
    <body>
    <div id="app">
      <ul>
          <li v-for = "todo in todos" v-bind:style="stylelist">
              <span>{{todo.text}}</span>
          </li>
      </ul>
      <input type="text" v-on:keyup.enter="addTodo" v-model="message"/>
      <button v-on:click = "add" v-bind:class="buttonStyle">增加书籍</button>
      <button v-on:click="remove" v-bind:class="buttonStyle">删除</button>
    </div>
     <script>
     var app = new Vue({
      el:'#app',
      data:{
        todos:[{text:'红楼梦'},{text:'水浒传'}],
        message:'',
        stylelist:{
          height:'30px',
          lineHeight:'30px',
          border:'1px solid red',
          textAlign:'center',
          background:'pink',
          color:'red'
        },
        buttonStyle:{
          'buttonstylelist':true
        }
      },
      methods:{
        remove:function(index){
          this.todos.splice(index,1)
        },
        addTodo:function(){
          var text = this.message.trim();
          if(text){
            this.todos.push({text:text});
            this.message=" ";
          }
        },
        add:function(){
          var text = this.message.trim();
          if(text){
            this.todos.push({text:text});
            this.message=" ";
          }
        }
      }
     })
     </script>
    </body>
    </html>
    

      

  • 相关阅读:
    2019.8.8 python day03
    2019.8.7 python进阶day02
    2019.8.6(python day01)
    2019.8.5
    2019.8.2
    2019.8.1
    2019.7.31
    2019.7.30
    面向对象进阶
    访问可见性问题和@property装饰器
  • 原文地址:https://www.cnblogs.com/TTTK/p/6226231.html
Copyright © 2020-2023  润新知