vue实现记事本功能

<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>记事本</title> <meta http-equiv="X-UA-Compatible" content="IE-edge"> <meta content="width=device-width,initial-scale=1"> <link type="text/css" href="https://www.jb51.net/article/bootstrap-3.3.7-dist/css/bootstrap.min.css" > <script type="text/javascript" src="https://www.jb51.net/article/vue.js"></script> </head> <body> <div> <div> <div> <h1>{{title}}</h1> <input type="text" placeholder="填写事务" v-model="newThing"/> <button type="button" v-on:click="addThing" v-on:keyup.enter="addThing">添加事务</button> </div> </div> <div> <div> <div> <ul> <li v-for="(item,index) in things" v-show="item.show">{{item.thing}} <button v-on:click="removeThing(index)" v-model="index">删除</button></li> </ul> </div> </div> </div> </div> </body> <script type="text/javascript"> var vue=new Vue({ el:'#app', data:{ title: '记事本', things:[ { thing:'', show:false } ], newThing:'', message:'待填写的事务为空!!' }, methods:{ addThing:function(){ if(this.newThing){ this.things.splice(0,0,{ thing:this.newThing, show:true }); this.newThing='' }else{ alert(this.message) } }, removeThing:function(index){ this.things[index].show=false } } }); </script> </html>

效果图:

vue实现记事本功能

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/ad2ff7b17eb7c64927a850f72eb1d433.html