使用Bootstrap和Vue實(shí)現(xiàn)用戶信息的編輯刪除功能
使用Bootstrap實(shí)現(xiàn)簡單的布局,并結(jié)合Vue進(jìn)行用戶信息的編輯刪除等功能,代碼如下
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>用戶信息編輯</title>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css" rel="external nofollow" >
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="bootstrap.js"></script>
<script type="text/javascript" src="vue.js"></script>
</head>
<body>
<div class="container">
<form role="form">
<div class="form-group">
<label for="username">用戶名</label>
<input type="text" name="username" class="form-control" placeholder="請(qǐng)輸入用戶名" v-model="username">
</div>
<div class="form-group">
<label for="password">密碼</label>
<input type="password" name="password" class="form-control" placeholder="請(qǐng)輸入密碼" v-model="password">
</div>
<div class="form-group">
<button type="button" class="btn btn-primary" @click="add()">添加</button>
<button type="reset" class="btn btn-danger">重置</button>
</div>
</form>
<hr>
<table class="table table-bordered table-hover">
<caption class="h3 text-info">用戶信息</caption>
<tr>
<th class="text-center">序號(hào)</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 myData">
<td>{{$index+1}}</td>
<td>{{item.name}}</td>
<td>{{item.password}}</td>
<td>
<button class="btn btn-danger" data-toggle="modal" data-target="#myModal" @click="nowIndex=$index">刪除</button>
</td>
</tr>
<tr v-show="myData.length!=0">
<td colspan="4" class="text-center">
<button class="btn btn-danger" data-toggle="modal" data-target="#myModal" @click="nowIndex=-2">刪除全部</button>
</td>
</tr>
<tr v-show="myData.length==0">
<td colspan="4" class="text-center">
<h5 class="text-muted">暫無信息...</h5>
</td>
</tr>
</table>
<!-- 模態(tài)框 -->
<div class="modal fade" id="myModal" role="dialog" tabindex="-1">
<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 text-danger">警告!</h4>
</div>
<div class="modal-body">
<h4 class="text-center">確認(rèn)刪除?</h4>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-primary">取消</button>
<button type="button" data-dismiss="modal" class="btn btn-danger" @click="deleteMsg(nowIndex)">確認(rèn)</button>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
new Vue({
el: ".container",
data: {
myData:[],
username:"",
password:"",
nowIndex:-100
},
methods:{
add:function(){
this.myData.push({
name:this.username,
password:this.password
});
this.username="";
this.password="";
},
deleteMsg:function(n){
if(n==-2){
this.myData=[];
}else{
this.myData.splice(n,1);
}
}
}
});
</script>
</body>
</html>
實(shí)現(xiàn)效果如下,因?yàn)橹皇呛唵蔚膶?shí)現(xiàn)編輯刪除的功能,因此密碼就直接顯示在表格中,沒有進(jìn)行加密顯示
整體布局界面

用戶信息編輯后添加

刪除數(shù)據(jù)

總結(jié)
以上所述是小編給大家介紹的使用Bootstrap和Vue實(shí)現(xiàn)用戶信息的編輯刪除功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
js中如何對(duì)嵌套數(shù)組進(jìn)行filter過濾
這篇文章主要介紹了js中如何對(duì)嵌套數(shù)組進(jìn)行filter過濾問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06
網(wǎng)站頁面自動(dòng)跳轉(zhuǎn)實(shí)現(xiàn)方法PHP、JSP(下)
很多時(shí)候我們需要Web頁具備有自動(dòng)跳轉(zhuǎn)功能,例如,論壇中的用戶登錄、發(fā)帖及回復(fù)或留言簿中的留言和回復(fù)等操作成功后,若用戶沒有任何鼠標(biāo)點(diǎn)擊操作,過了一定的時(shí)間,頁面自動(dòng)跳轉(zhuǎn)到預(yù)設(shè)的頁面。2010-08-08
javascript獲取不重復(fù)的隨機(jī)數(shù)的方法比較
js永不重復(fù)隨機(jī)數(shù)實(shí)現(xiàn)代碼比較2008-09-09
JavaScript中的單引號(hào)和雙引號(hào)報(bào)錯(cuò)的解決方法
數(shù)據(jù)中夾雜單引號(hào)(')或者雙引號(hào)("),這種語句往往會(huì)造成JavaScript報(bào)錯(cuò)。對(duì)此一般采用/'或者/"的解決2014-09-09

