vue.js做简易留言板

跟着网上的视频教程做了一个简易的留言板需要的自取,新手多多包涵

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>

<link rel="stylesheet" href="css/bootstrap.min.css" />
<script type="text/javascript" src="js/vue.js" ></script>
</head>
<body>
<div class="container" id="app">
<form role="form" >
<div class="form-group">
<label for="username">用户名</label>
<input class="form-control" type="text" placeholder="请输入姓名" id="username" v-model="username"/>
</div>
<div class="form-group">
<label for="age">年龄</label>
<input class="form-control" type="text" placeholder="请输入年龄" id="age" v-model="age"/>
</div>

<div class="form-group">
<input type="button" value="添加" class="btn btn-primary" v-on:click="add()"/>
<input type="reset" value="重置" class="btn btn-danger" />
</div>

<table class="table table-bordered table-hover">
<caption class="h2 text-center">用户信息表</caption>

<thead>
<tr>
<th class="text-center">序号</th>
<th class="text-center">姓名</th>
<th class="text-center">年龄</th>
<th class="text-center">操作</th>
</tr>

</thead>
 <tbody >
  <tr class="text-center" v-for="item in list">
                <td>{{$index+1}}</td>
                <td>{{item.name}}</td>
                <td>{{item.age}}</td>
               <td ><input type="button" value="删除" class="btn btn-danger"id="show" v-on:click="sh()"></td>
 
  </tr>
  <tr >
  <td colspan="4" class="text-right text-muted" v-show="list.length!=0">
  <input type="button" value="全部删除" class="btn btn-danger"  v-on:click="removall()"/>
  </td>
 
  </tr>
  <tr>
  <td colspan="4" class="text-center text-muted" v-show="list.length==0">
  <p>暂时没有数据...........</p>
  </td>
 
  </tr>
 </tbody>

</table>

</form>
<div class="modal" id="modal-1">


<div class="modal-dialog">


<div class="modal-content">


<div class="modal-header">

<h3 class="modal-title">删除</h3>
</div>


<div class="modal-body">
<div>确认要删除吗?</div>

</div>


<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" v-on:click="upHide()">关闭</button>
<button class="btn btn-success" v-on:click="upHide()" type="submit">确定</button>
</div>


</div>


</div>


</div>

</div>

<script type="text/javascript" src="js/jquery-3.1.1.min.js" ></script>
<script type="text/javascript" src="js/bootstrap.min.js" ></script>

<script>
window.οnlοad=function(){
new Vue({
el:"#app",
data:{
list:[],
username:"",
age:""

},
methods:{
add:function(){
this.list.push({
name:this.username,
                            age:this.age
})
this.username="";
this.age="";

},
sh:function(){
$("#modal-1").show();

},
upHide:function($index){
$("#modal-1").hide();
this.list.splice($index,1)

},
removall:function(){
this.list=[];
}

}


});
};
</script>
</body>
</html>

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值