欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue與bootstrap實(shí)現(xiàn)簡(jiǎn)單用戶信息添加刪除功能

 更新時(shí)間:2019年02月15日 13:28:05   作者:qq_39201210  
這篇文章主要為大家詳細(xì)介紹了vue與bootstrap實(shí)現(xiàn)簡(jiǎn)單用戶信息添加刪除功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue與bootstrap實(shí)現(xiàn)用戶信息添加刪除操作的具體代碼,供大家參考,具體內(nèi)容如下

小記:

1.v-model=""    用于input表單雙向數(shù)據(jù)綁定  邏輯層跟渲染層雙向綁定

2.v-on:click='add()'     click方法綁定 

3.v-for='(item,index) in myData'   遍歷數(shù)組  {{index}}      {{item.name}}      {{item.age}}   適用于vue版本2.0  

4.v-for='(item,index,key) in myData'   遍歷json  {{index}}      {{item}}      {{key}}   適用于vue版本2.0

5.v-on:click="currentUser=index"    直接綁定點(diǎn)擊事件改變邏輯層的數(shù)據(jù)  currentUser這里是邏輯層的數(shù)據(jù) 

6.v-show="myData.length!=0"   v-show根據(jù)后面的布爾值覺得顯示還是隱藏  可直接用邏輯層的數(shù)據(jù)進(jìn)行判斷

7.<div class="modal" role='dialog' id="layer"> modal  dialog為遮罩框 id用來聯(lián)系觸發(fā)元素

8. data-toggle='modal'   交替顯示隱藏遮罩框  data-target='#layer'    確定目標(biāo)模態(tài)框

9. data-dismiss='modal'  點(diǎn)擊后消失目標(biāo)元素

效果圖:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0" >
 <title>Document</title>
 <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet"  rel="external nofollow" >
 <script src='../jquery-3.2.1.min.js'></script>
 <script src='bootstrap.js'></script>
 <script src='vue.js'></script>
 <style>
 table td {vertical-align: middle !important;}
 </style>
</head>
<body>
<div class="container">
 
 <form action="" role='form' class="">
 <div class="form-group">
 <label for="username" class="">用戶名:</label>
 <input type="text" id="username" class="form-control" v-model="username" placeholder="請(qǐng)輸入用戶名">
 </div>
 <div class="form-group">
 <label for="age">年 齡:</label>
 <input type="text" id="age" class="form-control" v-model="age" placeholder="請(qǐng)輸入年齡">
 </div>
 <div class="form-group">
 <input type="button" value="添加" class="btn btn-primary" v-on:click='add()'>
 <input type="reset" value="重置" class="btn btn-warning">
 </div>
 </form>
 <table class="table table-bordered table-hover">
 <caption class="h4 text-info text-center">用戶信息表</caption>
 <tr class="text-danger">
 <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,index) in myData'>
 <td>{{index}}</td>
 <td>{{item.name}}</td>
 <td>{{item.age}}</td>
 <td>
 <button class="btn btn-danger btn-xs" data-toggle='modal' data-target='#layer' v-on:click="currentUser=index">刪除</button>
 </td>
 </tr>
 <tr v-show="myData.length!=0">
 <td colspan="4" class="text-right">
 <button class="btn btn-danger btn-xs" v-on:click='currentUser="all"' data-toggle='modal' data-target="#layer">全部刪除</button>
 </td>
 </tr>
 <tr v-show="myData.length==0">
 <td colspan="4" class="text-center">
 <p class="text-muted">暫無數(shù)據(jù)...</p>
 </td>
 </tr>
 </table>
 <div class="modal fade bs-example-modal-sm" role='dialog' id="layer">
 <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">確認(rèn)刪除嗎?</h4>
 </div>
 <div class="modal-body text-right">
  <button class="btn btn-primary btn-sm" data-dismiss='modal'>取消</button>
  <button class="btn btn-danger btn-sm" data-dismiss='modal' v-on:click="deleteuser()">確認(rèn)</button>
 </div>
 </div>
 </div>
 </div>
 
 
</div>
</body>
</html>
<script>
 var c = new Vue({
 el:'.container',
 data:{
 myData:[
 {name:"張三",age:20},
 {name:"李四",age:20},
 {name:"王五",age:20},
 ],
 username:"",
 age:"",
 currentUser :-100,
 },
 methods : {
 deleteuser :function(){
 if (this.currentUser == 'all') {
  this.myData = [];
 }else{
  this.myData.splice(this.currentUser,1);
 }
 },
 add : function(){
 if (this.username!=""&&this.age!=0) {
  this.myData.push({
  name:this.username,
  age:this.age
  })
 }
 },
 }
 })
</script>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue使用axios圖片上傳遇到的問題

    Vue使用axios圖片上傳遇到的問題

    后端寫個(gè)上傳圖片的接口可不是很簡(jiǎn)單,只需要讓這個(gè)字段限制為圖片格式,后臺(tái)做個(gè)保存的邏輯就完事了,前端處理還要牽扯到請(qǐng)求頭,數(shù)據(jù)格式的處理等等問題,按照老傳統(tǒng)把圖片按照字符串往接口put發(fā)現(xiàn)返回的全是400錯(cuò)誤,直到我知道了前端的FormData方法!
    2021-05-05
  • vue中v-for循環(huán)選中點(diǎn)擊的元素并對(duì)該元素添加樣式操作

    vue中v-for循環(huán)選中點(diǎn)擊的元素并對(duì)該元素添加樣式操作

    這篇文章主要介紹了vue中v-for循環(huán)選中點(diǎn)擊的元素并對(duì)該元素添加樣式操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • vue開發(fā)拖拽進(jìn)度條滑動(dòng)組件

    vue開發(fā)拖拽進(jìn)度條滑動(dòng)組件

    這篇文章主要為大家詳細(xì)介紹了vue開發(fā)拖拽進(jìn)度條滑動(dòng)組件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • VUE3+Element-plus中el-form的使用示例代碼

    VUE3+Element-plus中el-form的使用示例代碼

    這篇文章主要介紹了VUE3+Element-plus中el-form的使用示例代碼,本文通過圖文示例代碼相結(jié)合給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2024-07-07
  • vue路由的配置和頁面切換詳解

    vue路由的配置和頁面切換詳解

    這篇文章主要給大家介紹了關(guān)于vue路由的配置和頁面切換的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • vue實(shí)現(xiàn)表單數(shù)據(jù)的增刪改功能

    vue實(shí)現(xiàn)表單數(shù)據(jù)的增刪改功能

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)表單數(shù)據(jù)的增刪改功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Vue登錄主頁動(dòng)態(tài)背景短視頻制作

    Vue登錄主頁動(dòng)態(tài)背景短視頻制作

    這篇文章主要為大家詳細(xì)介紹了Vue登錄主頁動(dòng)態(tài)背景短視頻的制作方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • vue中v-cloak的作用和原理解析

    vue中v-cloak的作用和原理解析

    v-cloak原理是先通過樣式隱藏內(nèi)容,然后在內(nèi)存中進(jìn)行值的替換,將替換的內(nèi)容再反饋給界面,數(shù)據(jù)渲染完場(chǎng)之后,v-cloak 屬性會(huì)被自動(dòng)去除,本文詳細(xì)介紹vue中v-cloak的作用和原理解析,感興趣的朋友一起看看吧
    2023-09-09
  • vue通過video.js解決m3u8視頻播放格式的方法

    vue通過video.js解決m3u8視頻播放格式的方法

    這篇文章主要給大家介紹了關(guān)于vue通過video.js解決m3u8視頻播放格式的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • 基于better-scroll 實(shí)現(xiàn)歌詞聯(lián)動(dòng)功能的代碼

    基于better-scroll 實(shí)現(xiàn)歌詞聯(lián)動(dòng)功能的代碼

    BetterScroll 是一款重點(diǎn)解決移動(dòng)端(已支持 PC)各種滾動(dòng)場(chǎng)景需求的插件,BetterScroll 是使用純 JavaScript 實(shí)現(xiàn)的,這意味著它是無依賴的。本文基于better-scroll 實(shí)現(xiàn)歌詞聯(lián)動(dòng)功能,感興趣的朋友跟隨小編一起看看吧
    2020-05-05

最新評(píng)論