這次給大家?guī)鞡ootstrap與Vue操作用戶信息的添加與刪除,Bootstrap與Vue操作用戶信息添加與刪除的注意事項(xiàng)有哪些,下面就是實(shí)戰(zhà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> <p class="container"> <form role="form"> <p class="form-group"> <label for="username">用戶名</label> <input type="text" name="username" class="form-control" placeholder="請輸入用戶名" v-model="username"> </p> <p class="form-group"> <label for="password">密碼</label> <input type="password" name="password" class="form-control" placeholder="請輸入密碼" v-model="password"> </p> <p class="form-group"> <button type="button" class="btn btn-primary" @click="add()">添加</button> <button type="reset" class="btn btn-danger">重置</button> </p> </form> <hr> <table class="table table-bordered table-hover"> <caption class="h3 text-info">用戶信息</caption> <tr> <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 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)框 --> <p class="modal fade" id="myModal" role="dialog" tabindex="-1"> <p class="modal-dialog"> <p class="modal-content"> <p class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span>×</span></button> <h4 class="modal-title text-danger">警告!</h4> </p> <p class="modal-body"> <h4 class="text-center">確認(rèn)刪除?</h4> </p> <p 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> </p> </p> </p> </p> </p> <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)行加密顯示
相信看了本文案例你已經(jīng)掌握了方法,更多精彩請關(guān)注Gxl網(wǎng)其它相關(guān)文章!
推薦閱讀:
Angular操作表單增刪改查的驗(yàn)證功能
源生JS怎樣實(shí)現(xiàn)文件異步上傳
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com