第一节
<script type="text/javascript"src="vue.j/vue.js">
</script>
<style type="text/css">
input{
width: 100%;
height: 33px;
border-radius: 5px;
font-size: 8px;
}
p{
margin-top: 25px;
}
.box{
margin-top: 20px;
}
tr{
height:40px;
}
</style>
<body>
<div class="container" id="itany">
<h1 class="text-center">添加用户</h1>
<p>姓名</p>
<input type="text" v-model="str" placeholder="请输入姓名">
<p>年龄</p>
<input type="text" v-model="ben" placeholder="请输入年龄">
<p>邮箱</p>
<input type="text" v-model="sen" placeholder="请输入邮箱">
<div class="box text-center">
<button class="btn btn-primary" v-on:click="add">添加</button>
<button class="btn btn-success" v-on:click="chong">重置</button>
</div>
<table border="" cellspacing="" cellpadding="" width="100%" style="text-align: center;">
<tr>
<td>序号</td>
<td>姓名</td>
<td>年龄</td>
<td>邮箱</td>
<td>操作</td>
</tr>
<tr v-for='(v,index) in arr'>
<td>{{v.num}} </td>
<td>{{v.name}}</td>
<td>{{v.old}}</td>
<td>{{v.email}}</td>
<td><button v-on:click="the(index)">删除</button></td>
</tr>
</table>
</div>
<script>
new Vue({
el:'#itany',
data:{
arr:
[
{num:'1',name:'tom',old:'18',email:'tom@126.com'},
{num:'2',name:'jack',old:'19',email:'jack@126.com'},
{num:'3',name:'amy',old:'20',email:'amy@126.com'}
],
str:'',
ben:'',
sen:'',
},
methods:{
add:function(){
this.arr.push({num:this.arr.length+1,name:this.str,old:this.ben,email:this.sen})
},
the:function(ind){
this.arr.splice(ind,1)
},
}
})
</script>