日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

使用Bootstrap + Vue.js实现 添加删除数据

發布時間:2025/3/17 vue 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用Bootstrap + Vue.js实现 添加删除数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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

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

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

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

<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(index)">刪除</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:''},methods:{add:function(){this.myData.push({name:this.username,age:this.age});this.username='';this.age='';},deleteMsg:function(index){this.myData.splice(index,1) },all:function(){this.myData = [];}}})}

?

?

如果我的內容對你有幫助,歡迎打賞

轉載于:https://www.cnblogs.com/hezihao/p/6445840.html

總結

以上是生活随笔為你收集整理的使用Bootstrap + Vue.js实现 添加删除数据的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。