vue bootstrap小例子一枚

vue和angular非常像都是MVVM。道理都是想通的,就是语法的差异 

我觉得vue和angular区别: 

1.vue更轻,更便捷,适用于移动开发 

2.vue更简单。。 

angular和vue指令的差别大致就是 ng-xxx和v-xxx。 
vue是用过new Vue创建实例,然后在属性data绑定数据,在属性methods里添加方法。 
vue的循环遍历是 v-for=“” ,事件是 v-on:clicl =“”;

直接上代码。

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <link href="https://www.jb51.net/bootstrap.css" > <style> tr{ vertical-align: inherit; } </style> <script src="https://www.jb51.net/jquery.js"></script> <script src="https://www.jb51.net/bootstrap.js"></script> <script src="https://www.jb51.net/node_modules/vue/dist/vue.js"></script> <script> window.onload= function(){ var vm = new Vue({ el:'.container', data:{ myData:[], username:'', age:'' }, methods:{ add:function(){ this.myData.push({ name:this.username, age:this.age }); this.username=""; this.age=""; }, reset:function(){ this.username=""; this.age=""; }, del:function(index){ this.myData.splice(index,1) }, delAll:function(){ this.myData=[]; } } }) } </script> </head> <body> <div> <form role="form"> <div> <label for="username">用户名:</label> <input placeholder="输入用户名" type="text" v-model="username"> </div> <div> <label for="age">年龄:</label> <input placeholder="输入年龄" type="text" v-model="age"> </div> <div> <input type="button" v-on:click="add()" value="添加"> <input type="button" v-on:click="reset()" value="重置"> </div> </form> <hr> <table> <caption>用户信息表</caption> <tr> <td>序号</td> <td>名字</td> <td>年龄</td> <td>操作</td> </tr> <tr v-for="(item,index) in myData"> <td>{{index+1}}</td> <td>{{item.name}}</td> <td>{{item.age}}</td> <td> <button v-on:click="del(index)" data-toggle="dialog" data-target="#layer" >删除</button> </td> </tr> <tr v-show="myData.length!=0"> <td colspan="4"> <button v-on:click="delAll()">删除全部</button> </td> </tr> <tr v-show="myData.length==0"> <td colspan="4"> <p>暂无数据</p> </td> </tr> </table> </div> </body> </html>

效果:

vue bootstrap小例子一枚

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

转载注明出处:https://www.heiqu.com/wyxdpp.html