Vue实现一个简单的todolist

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="app">
         <input type="text" v-model='inputVal'>
         <button @click='handleAdd'>提交</button> 
         <ul>
            <li v-for='(item,index) in list'>{{item}}
               <button @click='handleDelete(index)'>删除</button>
            </li>
         </ul>
   </div>
</body>
</html>
<script src="../vue.js"></script>
<script>
    new Vue({
        el:"#app",
        data:{
           inputVal:'',
           list:[]
        },
        methods:{
            handleAdd(){
                this.list.push(this.inputVal);
                this.inputVal = ''
            },
            handleDelete(index){
                this.list.splice(index,1)
            }
        }
    })
</script>

  

posted @ 2019-08-02 13:36  Yi只猴  阅读(1458)  评论(0编辑  收藏  举报