加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
userManage.html 5.44 KB
一键复制 编辑 原始数据 按行查看 历史
lm_mmmmm 提交于 2017-09-10 03:55 . html vue基本用法示例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>用户管理</title>
<script src="js/vue.js"></script>
<link rel="stylesheet" href="bootstrap/bootstrap.css">
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
window.onload = function () {
var vm = new Vue({
el: '#app',
data: {
users: [
{ name: "LiMeng", age: 18, email: "limeng@qq.com" },
{ name: "zhangSan", age: 28, email: "zhangsan@qq.com" }
],
user: {},
name: "",
nowIndex: -1 //当前索引值
},
methods: {
addUser: function () {
this.users.push(this.user);
this.user = {};
},
delUser: function () {
if (this.nowIndex === -1) {
this.users = [];
} else {
this.users.splice(this.nowIndex, 1); //指定位置开始删除1个
}
}
}
})
}
</script>
</head>
<body>
<div id="app">
<div class="col-sm-10 col-sm-offset-1">
<h2 class="text-center">添加用户</h2>
<div class="form-horizontal">
<form class="form-group">
<label for="name" class="control-label col-sm-2 col-sm-offset-2">姓 名: </label>
<div class="col-sm-6">
<input type="text" class="form-control" id="name" v-model="user.name" placeholder="请输入姓名">
</div>
</form>
<form class="form-group">
<label for="age" class="control-label col-sm-2 col-sm-offset-2">年 龄: </label>
<div class="col-sm-6">
<input type="text" class="form-control" id="age" v-model="user.age" placeholder="请输入年龄">
</div>
</form>
<form class="form-group">
<label for="email" class="control-label col-sm-2 col-sm-offset-2">邮 箱: </label>
<div class="col-sm-6">
<input type="text" class="form-control" id="email" v-model="user.email" placeholder="请输入邮箱">
</div>
</form>
<div class="form-group text-center">
<input type="button" value="添 加" class="btn btn-primary" v-on:click="addUser">
<input type="button" value="重 置" class="btn btn-primary">
</div>
</div>
</div>
<hr>
<div class="col-sm-10 col-sm-offset-1">
<table class="col-sm-10 table table-bordered table-hover ">
<caption class="h3 text-center text-info">用户列表</caption>
<thead>
<tr>
<th class="text-center">姓名</th>
<th class="text-center">序号</th>
<th class="text-center">年龄</th>
<th class="text-center">邮箱</th>
<th class="text-center">操作</th>
</tr>
</thead>
<tbody>
<tr v-for="(user,index) in users">
<td class="text-center">{{index}}</td>
<td class="text-center">{{user.name}}</td>
<td class="text-center">{{user.age}}</td>
<td class="text-center">{{user.email}}</td>
<td class="text-center">
<button class="btn btn-danger btn-sm" data-toggle="modal" data-target="#del" v-on:click="nowIndex=index">删 除</button>
</td>
</tr>
<tr>
<td colspan="5" class="text-right">
<button class="btn btn-danger btn-sm" data-toggle="modal" data-target="#del">删除所有</button>
</td>
</tr>
</tbody>
</table>
</div>
<!--模态框-->
<div class="modal" id="del">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close" data-dismiss="modal">
<span>&times;</span>
</button>
<h4 class="modal-title" v-show="nowIndex !== -1">你确定要删除:{{users[nowIndex]?users[nowIndex].name:""}}用户吗?</h4>
<h4 class="modal-title" v-show="nowIndex === -1">你确定要删除所有用户吗?</h4>
</div>
<div class="modal-body text-center">
<button class="btn btn-primary" data-dismiss="modal">取消</button>
<button class="btn btn-primary" data-dismiss="modal" v-on:click="delUser">确定</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化