vuejs学习笔记 v-model v-on v-bind computed vue三目运算符
html>html lang="en">head>meta charset="UTF-8">link rel="stylesheet" href="./css/bootstrap.min.css">title>Titletitle>head>style>.complete{color: #00a65a;text-d
·
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="./css/bootstrap.min.css"> <title>Title</title> </head> <style> .complete{ color: #00a65a; text-decoration: line-through; } </style> <body> <div class="container" id ='app'> <div class='row'> <div class="panel"> <div class="panel-heading"> VUEJS {{ arrCount }} </div> <div class="panel-body"> <h1> {{ message }} </h1> <input type="text" class="form-control" v-model="message"> <ul class="list-group"> <li class="list-group-item" v-bind:class="{'complete':arrs.complete}" v-for="(arrs,index) in arr"> {{ arrs.title }} <button class="btn btn-warning btn-xs pull-right" v-on:click="deleteArr(index)"> delete </button> <button class="btn btn-xs pull-right" v-bind:class="[arrs.complete ? 'btn-success':'btn-danger']" v-on:click="onsComplete(arrs)"> {{ arrs.complete? 'complete':'off' }} </button> </li> </ul> <form action="" v-on:submit.prevent = 'addArr(newArr)'> <div class="form-group"> <input type="text" class="form-control" v-model="newArr.title" placeholder="title"> </div> <div class="form-group"> <button class="btn btn-success">add arr</button> </div> </form> </div> </div> </div> </div> </body> <script src="js/vue.js"></script> <script> new Vue({ el:'#app', data:{ message:'hello word', arr:[ {id:1,title:'trc',age:'20',complete:false} ], newArr: {id:null,title:'',age:null,complete:false} }, computed:{ arrCount:function(){ return this.arr.length } }, methods:{ addArr:function(newArr){ this.arr.push(newArr); this.newArr = {id:null,title:'',age:null}; }, deleteArr:function(index){ console.log(index); this.arr.splice(index,1); }, onsComplete:function(arrs){ arrs.complete = ! arrs.complete; } } }); </script> </html>
更多推荐
已为社区贡献1条内容
所有评论(0)