国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

使用Bootstrap + Vue.js實現添加刪除數據示例

2019-11-19 17:24:55
字體:
來源:轉載
供稿:網友

界面首先需要引入bootstrap的css和bootstrap的js文件,還有vue.js和jQuery.js才可以看見效果。

這里提供bootstrap的在線文件給大家引用:

<!-- 最新版本的 Bootstrap 核心 CSS 文件 --><link rel="stylesheet"  rel="external nofollow" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- 最新的 Bootstrap 核心 JavaScript 文件 --><script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

效果如下圖所示,輸入用戶名和年齡,點擊添加,數據會自動添加到下面的用戶信息表內。當沒有數據時,用戶信息表顯示:暫無數據……,當有數據時,顯示 刪除全部 按鈕,這里為了方便快捷,我沒有做刪除按鈕的彈出框,所以 點擊刪除按鈕 會直接刪除掉當前這條數據。

 <div class="container" id="box">    <form role="form">      <div class="form-group">        <label for="username">用戶名:</label>        <input type="text" id="username" class="form-control" placeholder="請輸入用戶名" v-model="username" />      </div>      <div class="form-group">        <label for="age">年齡:</label>        <input type="text" id="age" class="form-control" placeholder="請輸入年齡" v-model="age" />      </div>      <div class="form-group">        <input type="button" value="添加" class="btn btn-primary" v-on:click="add()" />        <input type="reset" value="重置" class="btn btn-danger" />      </div>    </form>    <hr>    <table class="table table-bordered table-hover">      <caption class="text-center">用戶信息表</caption>      <tr class="text-danger">        <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, index) in myData">        <td>{{index+1}}</td>         <td>{{item.name}}</td>        <td>{{item.age}}</td>        <td>          <button class="btn btn-primary btn-sm" v-on:click="deleteMsg()">刪除</button>        </td>      </tr>      <tr v-show="myData.length!==0">        <td colspan="4" class="text-right">          <button class="btn btn-danger" v-on:click="all()">刪除全部</button>        </td>      </tr>      <tr v-show="myData.length==0">        <td colspan="4" class="text-center text-muted">          <p>暫無數據……</p>        </td>      </tr>    </table>  </div>
window.onload = function(){    new Vue({      el:"#box",      data:{        myData:[],        username:'',        age:'',        nowIndex:-100      },      methods:{        add:function(){          this.myData.push({            name:this.username,            age:this.age          });          this.username='';          this.age='';        },        deleteMsg:function(){          this.myData.splice(0,1)        },        all:function(){          this.myData = [];        }      }    })  }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 普兰县| 历史| 九江市| 茂名市| 聊城市| 雅江县| 班戈县| 阿城市| 中方县| 都兰县| 海林市| 修武县| 安阳市| 清水河县| 新建县| 宣化县| 榆树市| 山阴县| 沁源县| 石门县| 齐齐哈尔市| 梁平县| 凉城县| 金门县| 九寨沟县| 福泉市| 桦南县| 安泽县| 牡丹江市| 柘城县| 荣昌县| 汕头市| 东光县| 江达县| 光泽县| 海原县| 化隆| 安国市| 历史| 惠水县| 名山县|