bootstrap+vue

版权声明:A_芦瑞华_i_DO.欢迎转载 https://blog.csdn.net/weixin_43067223/article/details/85223017

代码

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>table</title>
		<link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css">
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
		<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
		<script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
		<script src="https://cdn.bootcss.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
		<script src="../js/vue.js"></script>
	</head>

	<body>
		<div id="app">
			<div class="row mx-auto w-75">
				<div class="col-6">
					<div class="btn-group">
						<button type="button" class="btn btn-outline-info btn-sm" data-toggle="modal" data-target="#myModal">新增</button>
						<button type="button" class="btn btn-outline-primary btn-sm" @click="saveRows">保存</button>
					</div>
					<button type="button" class="btn btn-outline-warning btn-sm" @click="delRows">删除</button>
				</div>
				<div class="col-6">
					<div class="input-group">
						<input type="text" class="form-control input-group-sm" placeholder="输入设备编号进行搜索">
						<span class="input-group-btn">
                        <button class="btn btn-default" type="button"><i class="fa fa-search"></i></button>
                    </span>
					</div>
				</div>
			</div>
			<div class="row mx-auto w-75">
				<div class="col-12">
					<table class="table table-hover table-success">
						<thead class="thead-default">
							<tr>
								<th><input type="checkbox"></th>
								<th>序号</th>
								<th>设备编号</th>
								<th>设备名称</th>
								<th>设备状态</th>
								<th>采购日期</th>
								<th>设备管理员</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(facility,index) in facilities">
								<td><input type="checkbox" :value="index" v-model="checkedRows"></td>
								<td>{{index+1}}</td>
								<td>{{facility.code}}</td>
								<td>{{facility.name}}</td>
								<td>{{facility.states}}</td>
								<td>{{facility.date}}</td>
								<td>{{facility.admin}}</td>
							</tr>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</body>
	<script>
		new Vue({
			el: "#app",
			data: {
				facilities: [{
						code: "A2017-001",
						name: "3800充电器",
						states: "正常",
						date: "2017-01-21",
						admin: "andy"
					},
					{
						code: "A2017-002",
						name: "Lenovo Type-c转接器",
						states: "正常",
						date: "2017-01-21",
						admin: "zero"
					}
				],
				checkAll: false, // 是否全选
				checkedRows: [], // 选中的行标,用于删除行
				newRow: {} // 新增的行数据,用于新增行
			},
			methods:{
				delRows:function () {
                if (this.checkedRows.length <= 0){//是否选中判断
                    alert("您未选择需要删除的数据");
                    return false;
                }
                if (!confirm("您确定要删除选择的数据吗?")){//删除确认
                    return false;
                }

                for(var i=0;i<this.checkedRows.length;i++){//循环获取选中的行标
                    var checkedRowIndex = this.checkedRows[i];
                    /**根据下标移除数组元素*/
                    this.facilities = $.grep(this.facilities,function (facility,j) {
                        return j != checkedRowIndex;
                    });
                }
                this.checkedRows = [];//清空选中行数据
           }
			}
		})
	</script>

</html>

页面效果

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43067223/article/details/85223017