先上效果图:
其中用到的知识点:有bootstrap和bootstrap.js,以及Vue的常用指令
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ToDoList</title>
<link rel="stylesheet" href="lib/bootstrap.min.css">
<script src="lib/jquery-1.7.2.js"></script>
<script src="lib/bootstrap.js"></script>
<script src="lib/vue.js"></script>
<script type="text/javascript">
window.onload = function () {
var vue = new Vue({
el: '.box',
data: {
userData: [],
username: '',
password: '',
nowIndex: -100
},
methods: {
add: function () {
this.userData.push({
name: this.username,
passwd: this.password
});
//清空
this.username = '';
this.password = '';
}
,
delet: function (n) {
if (n == -2) {
this.userData = [];
} else {
this.userData.splice(n, 1);
}
},
}
})
}
</script>
</head>
<body>
<div class="box">
<form role="form">
<div class="form-group">
<label for="username">用户名</label>
<input type="text" id="username" class="form-control" placeholder="请输入用户名" v-model="username">
</div>
<div class="form-group">
<label for="password">密码</label>
<input type="password" id="password" class="form-control" placeholder="请输入密码" v-model="password">
</div>
<div class="form-group text-center">
<input type="button" value="提交" class="btn btn-primary text-left" @click="add">
<input type="reset" value="重置" class="btn btn-danger">
</div>
</form>
<hr>
<div class="form-group">
<table class="table table-bordered table-hover">
<caption class="h3 text-info">用户信息表</caption>
<tr class="text-warning">
<th class="text-center">序号</th>
<th class="text-center">姓名</th>
<th class="text-center">密码</th>
<th class="text-center">操作</th>
</tr>
<tr class="text-center" v-for="item in userData">
<td>{{$index+1}}</td>
<td>{{item.name}}</td>
<td>{{item.passwdsss}}</td>
<td>
<button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#layer"
@click="nowIndex=$index">删除
</button>
</td>
</tr>
<tr v-show="userData.length!=0">
<td colspan="4" class="text-right">
<button class="btn btn-danger btn-sm" @click="nowIndex=-2" data-toggle="modal" data-target="#layer">
删除全部
</button>
</td>
</tr>
<tr v-show="userData.length==0">
<td colspan="4" class="text-center text-muted">
<p>暂无数据....</p>
</td>
</tr>
</table>
</div>
<!--模态框 弹出框-->
<div role="dialog" class="modal fade bs-example-modal-sm" id="layer">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<span>×</span>
</button>
<h4 class="modal-title">确认删除么?</h4>
</div>
<div class="modal-body text-right">
<button data-dismiss="modal" class="btn btn-primary btn-sm">取消</button>
<button data-dismiss="modal" class="btn btn-danger btn-sm" @click="delet(nowIndex)">确认</button>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>