本文环境:windows7、vue2.9.6,该方法适用于所有品牌的电脑。
vue.js做删除的方法:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>图书馆增加书</title> <script src="js/vue.js"></script> <style> ul{ list-style: none; width:100px; height:auto; } .buttonstylelist{ width: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>
以上就是vue.js怎么做删除的详细内容,更多请关注其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。