zoukankan      html  css  js  c++  java
  • vue.js--基础 事件结合双向数据绑定实现todolist,增加和删除功能

    原理很简单,写一个input框,定义一个空的list,当在input中增加数据时,就往list中添加数据,然后在循环这个list的数据,删除数据就是调用list中的splice

    <template>
    
    <div id="app">
    <h1>{{ msg }}</h1>
    <input type="text" v-model="todo"/>
    <button @click="addData">增加数据</button>
    <hr>
    <br>
    <ul>
    <li v-for="(item,key) in list">
    {{item}}--------<button @click="delteData(key)">删除数据</button>
    </li>
    </ul>
    </div>
    </template>
    
    <script>
    /*
    双向数据绑定,用于表单,
    */
    export default {
    name: 'app',
    data () {
    return {
    msg: 'hello',
    todo: '',
    list:[]
    }
    },methods:{
    addData(){
    //alert("111")
    this.list.push(this.todo);
    this.todo='';
    },delteData(key){
    this.list.splice(key,1)
    }
    }
    }
    
    </script>
    <style>
    
    
    h1, h2 {
    font-weight: normal;
    }
    .box{
     100px;
    height: 100px;
    background-color: #42b983
    }
    </style>
    

      

  • 相关阅读:
    php设计模式之观察者模式
    git tag 相关命令
    git 命令
    phpstudy 配置本地站点的ssl证书
    b
    __invoke,try{}catch(){},microtime(),is_callable()
    json_encode 中文不乱码
    php ::class
    yii 2 美化url
    JNIjw03
  • 原文地址:https://www.cnblogs.com/chongyou/p/9505357.html
Copyright © 2011-2022 走看看