html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.staticfile.org/vue/2.7.0/vue.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>
<body>
<div id="box">
<div class="head1">
<p><span>用户权限/</span>用户列表</p>
</div>
<div class="bottom">
<p><span><button id="tianjia" @click="tianjia">添加</button></span>
<span>角色 <input type="text" id="ipt"placeholder="全部" v-model="ipt"></span>
<span><button id="sousuo"@click="sousuo()">搜索</button></span>
<span>
<input id="ipt1" type="text" placeholder="修改后称昵" v-model="xgcn">
<input id="ipt1" type="text" placeholder="修改后用户" v-model="xgyh">
<input id="ipt1" type="text" placeholder="修改后角色" v-model="xgjs">
<button id="xgbc" @click="qrbc()">点击修改保存</button>
</span>
</p>
<table id="tab" border="1">
<tr id="tr1">
<th>序号</th>
<th>称昵</th>
<th>用户名</th>
<th>角色</th>
<th>创建时间</th>
<th>最近修改时间</th>
<th>管理</th>
</tr>
<tbody id="tbd">
<tr v-for="(item,index) in str1==0?arr:arr3">
<td>{{item.id}}</td>
<td>{{item.chengni}}</td>
<td>{{item.yonghuming}}</td>
<td>{{item.jiaose}}</td>
<td>9.27</td>
<td>9.27</td>
<td><button class="xiugai" @click="xiugai(index)">修改</button>
<button class="shanchu" @click="del(index)">删除</button></td>
</tr>
</tbody>
</table>
</div>
<div class="bottom1" v-show="show1">
<input type="text" placeholder="称昵" v-model="chengni"><br>
<input type="text" placeholder="用户名" v-model="yonghuming"><br>
<input type="text" placeholder="角色" v-model="jiaose"><br>
<button id="queren" @click="queren">确认添加</button><button id="quxiao" @click="quxiao">取消</button>
</div>
</div>
</body>
</html>
style:
<style>
* {
margin: 0;
padding: 0;
}
ul li {
list-style: none;
}
body {
background: #e7e6e6;
}
.head1 {
margin-left: 20px;
margin-top: 10px;
margin-bottom: 10px;
}
.head1 p span {
color: #767676;
}
.bottom {
width: 92rem;
height: 700px;
background: #fff;
margin-top: 20px;
margin: auto;
position: relative;
}
.bottom p {
padding-top: 20px;
}
.bottom p span {
margin-left: 25px;
}
.bottom p span button {
width: 70px;
height: 35px;
background: #0076fb;
color: #fff;
border-radius: 10px;
border: none;
}
#ipt {
width: 400px;
height: 32px;
border: 1px solid #ccc;
outline: none;
border-radius: 5px;
}
#ipt1{
width: 100px;
height: 32px;
border: 1px solid #ccc;
outline: none;
border-radius: 5px;
margin-left: 5px;
margin-right: 5px;
}
#tab {
width: 1400px;
height: 30px;
margin-left: 25px;
margin-top: 10px;
border-collapse: collapse;
}
.bottom1 {
width: 400px;
height: 300px;
background: rgba(0, 0, 0, 0.3);
border-radius: 10px;
position: absolute;
top: 190px;
left: 500px;
/* display: none; */
}
.bottom1 input {
width: 200px;
height: 40px;
border: none;
margin-left: 100px;
margin-top: 15px;
border-radius: 10px;
}
.bottom1 button {
width: 80px;
height: 40px;
border: none;
margin-left: 80px;
margin-top: 40px;
border-radius: 10px;
}
#queren {
background: #0076fb;
color: #fff;
}
#quxiao {
background: #767676;
color: #fff;
}
#tbd tr td {
height: 50px;
text-align: center;
}
.xiugai {
width: 80px;
height: 40px;
border: none;
color: #fff;
background: green;
border-radius: 20px;
}
.shanchu {
width: 80px;
height: 40px;
border: none;
color: #fff;
background: rgb(158, 8, 8);
border-radius: 20px;
margin-left: 10px;
}
#xgbc{
width: 100px;
}
table tr:nth-child(odd){
background: rgb(242, 144, 144);
}
table tr:nth-child(even){
background: rgb(149, 149, 237);
}
table tr:hover{
background: rgb(228, 228, 153);
}
#tr1{
background: #fff;
}
</style>
script:
<script>
new Vue({
el: '#box',
data() {
return {
show1: false,
chengni: '',
yonghuming: '',
jiaose: '',
ipt: '',
str1:0,
arr3:'',
xgcn:'',
xgyh:'',
xgjs:'',
index:'', //点击修改后,把修改的下标传进来,(这里的index是它的空值)
arr: [{
id: 1,
chengni: 'zhangsa',
yonghuming: 12,
jiaose: 123
},
{
id: 1,
chengni: 'zhangsa',
yonghuming: 12,
jiaose: 123
},
{
id: 1,
chengni: 'zhangsa',
yonghuming: 12,
jiaose: 123
}
]
}
},
methods: {
// 点击添加显示
tianjia() {
this.show1 = true
},
// 点击取消隐藏
quxiao() {
this.show1 = false
},
// 确认添加
queren() {
let obj = {
id: 1,
chengni: this.chengni,
yonghuming: this.yonghuming,
jiaose: this.jiaose,
}
this.arr.push(obj)
},
// 删除
del(a) {
if (confirm('确定要删除吗')==true){
this.arr.splice(a, 1)
}else{
return false;
}
},
// 修改
xiugai(index){
this.index = index
this.xgcn= this.arr[index].chengni
this.xgyh= this.arr[index].yonghuming
this.xgjs= this.arr[index].jiaose
},
// 点击确认保存
qrbc(){
this.arr[this.index].chengni=this.xgcn
this.arr[this.index].yonghuming=this.xgyh
this.arr[this.index].jiaose=this.xgjs
},
// 查询
sousuo() {
if (this.ipt == '') {
this.str1 = 0
return
}
this.str1 = 2
this.arr3 = this.arr.filter((res) => {
return res.chengni.includes(this.ipt)
})
console.log(this.ipt);
}
},
})
</script>