位置: IT常识 - 正文

Vue--》搭配Bootstrap实现Vue的列表增删功能(vue怎么用bootstrap)

发布时间:2024-01-17
Vue--》搭配Bootstrap实现Vue的列表增删功能

推荐整理分享Vue--》搭配Bootstrap实现Vue的列表增删功能(vue怎么用bootstrap),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:vue结合bootstrap,vue怎么用bootstrap,vue和bootstrap混用,vue-bootstrap,vue +bootstrap,vuecli bootstrap,vue-bootstrap,vue+bootstrap4,内容如对您有帮助,希望把文章链接给更多的朋友!

在日常开发中,我们可以用 “拿来主义” 借助Bootstarp现成的一些样式,快速生成我们想要的页面布局,避免书写大量的HTML和CSS代码,省下了许多不必要的时间。

当我们想要生成表单表格时我们可以查看Bootstrap的官方文档,来选择我们想要的样式,并根据自己的一些实际情况或者个人喜好进行一定的修改。了解Bootstrap

为了直接搭配Vue使用,我们把表单代码直接复制到 root 容器里面。

<div id="root"> <!-- 卡片区域 --> <div class="card"> <div class="card-header">添加水果</div> <div class="card-body"> <!-- 添加品牌的表单区域 --> <form> <div class="form-row align-items-center"> <div class="col-auto"> <div class="input-group mb-2"> <div class="input-group-prepend"> <div class="input-group-text">水果名称</div> </div> <input type="text" class="form-control" placeholder="请输入水果名字"> </div> </div> <div class="col-auto"> <button type="submit" class="btn btn-primary mb-2">添加</button> </div> </div> </form> </div> </div></div>

这边借助一下Bootstrap中的card(卡片)进行布局,扩充一下宽度。 

接下来我们在借助Bootstrap生成一个表格部分:

<table class="table table-border table-hover table-striped"> <thead> <tr> <th scope="col">ID</th> <th scope="col">水果名称</th> <th scope="col">状态</th> <th scope="col">添加时间</th> <th scope="col">操作</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>苹果</td> <td> <div class="custom-control custom-switch"> <input type="checkbox" class="custom-control-input" id="customSwitch1"> <label class="custom-control-label" for="customSwitch1">已禁用</label> </div> </td> <td>时间</td> <td> <a href="javascript:'">删除</a> </td> </tr> </tbody></table>

表格结构写完之后,接下里我们就要使用Vue对表格进行填充数据了。

<script src="/Vue.js/vue.js"></script><script> Vue.config.productionTip = false; //阻止 vue 在启动时生成生产提示 const vm = new Vue({ data: { list: [ { id: 1, name: '苹果', status: true, time: new Date() }, { id: 2, name: '香蕉', status: true, time: new Date() }, { id: 3, name: '葡萄', status: false, time: new Date() }, { id: 4, name: '桃子', status: true, time: new Date() }, ] } }) vm.$mount('#root')</script>Vue--》搭配Bootstrap实现Vue的列表增删功能(vue怎么用bootstrap)

接下里给删除操作绑定点击事件,如下:

给a链接绑定一个删除的点击事件。

我们使用filter进行过滤掉删除的数组,当前循环项的item.id不等于我们要删的id,就返回。

接下来我们实现水果的添加功能。

给输入框设置双向绑定事件,给表单设置提交事件并添加阻止事件。

定义用户输入的水果名称以及下一个可用的ID :

给绑定的add事件添加判断行为:

现在基本的添加删除功能已经完成,请看效果:

完整代码:

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="/Bootstrap/bootstrap.css"> <style> body { padding: 15px; } </style></head><body> <div id="root"> <!-- 卡片区域 --> <div class="card"> <div class="card-header">添加水果</div> <div class="card-body"> <!-- 添加品牌的表单区域 --> <form @submit.prevent="add"> <div class="form-row align-items-center"> <div class="col-auto"> <div class="input-group mb-2"> <div class="input-group-prepend"> <div class="input-group-text">水果名称</div> </div> <input type="text" class="form-control" placeholder="请输入水果名字" v-model.trim="brand"> </div> </div> <div class="col-auto"> <button type="submit" class="btn btn-primary mb-2">添加</button> </div> </div> </form> </div> </div> <!-- 表格区域 --> <table class="table table-border table-hover table-striped"> <thead> <tr> <th scope="col">ID</th> <th scope="col">水果名称</th> <th scope="col">状态</th> <th scope="col">添加时间</th> <th scope="col">操作</th> </tr> </thead> <tbody> <tr v-for="item in list" :key="item.id"> <th scope="row">{{item.id}}</th> <td>{{item.name}}</td> <td> <div class="custom-control custom-switch"> <input type="checkbox" class="custom-control-input" :id="'customSwitch'+item.id" v-model="item.status"> <label class="custom-control-label" :for="'customSwitch'+item.id" v-if="item.status">已启用</label> <label class="custom-control-label" :for="'customSwitch'+item.id" v-else>已禁用</label> </div> </td> <td>{{item.time}}</td> <td> <a href="javascript:'" @click="remove(item.id)">删除</a> </td> </tr> </tbody> </table> </div> <script src="/Vue.js/vue.js"></script> <script> Vue.config.productionTip = false; //阻止 vue 在启动时生成生产提示 const vm = new Vue({ data: { // 用户输入的水果名称 brand: '', // nextID是下一个可用的 ID nextId: 5, list: [ { id: 1, name: '苹果', status: true, time: new Date() }, { id: 2, name: '香蕉', status: true, time: new Date() }, { id: 3, name: '葡萄', status: false, time: new Date() }, { id: 4, name: '桃子', status: true, time: new Date() }, ] }, methods: { // 点击链接删除对应的水果 remove (id) { this.list = this.list.filter(item => item.id !== id) }, // 阻止表单的默认提交行为 // 如果判断到brand的值为空字符串,则return出去 add () { if (this.brand === '') return alert('必须输入水果') // 如果没有被return出去,应该执行添加逻辑 // 1.先把要添加的水果对象整理出来 const obj = { id: this.nextId, name:this.brand, status:true, time:new Date() } // 2.往this.list数组中push步骤一中得到的对象 this.list.push(obj) // 3.清空this.brand让this.nextID自增+1 // this.brand='' this.nextId++ }, } }) vm.$mount('#root') </script></body></html>
本文链接地址:https://www.jiuchutong.com/zhishi/298780.html 转载请保留说明!

上一篇:Ubuntu20.04安装OpenCV(ubuntu20.04安装opencv3.4)

下一篇:VMware虚拟机安装Ubuntu 2022最新版详细图文安装教程(VMware虚拟机安装+Ubuntu下载+VMware虚拟机配置运行)(vmware虚拟机安装在移动硬盘)

  • nova5外屏碎了(nova5pro外屏碎了)

    nova5外屏碎了(nova5pro外屏碎了)

  • 苹果xr为何每天不停要验证id(苹果xr一天多次黑屏什么情况)

    苹果xr为何每天不停要验证id(苹果xr一天多次黑屏什么情况)

  • 华为屏幕录制怎么录制系统声音(华为屏幕录制怎么打开)

    华为屏幕录制怎么录制系统声音(华为屏幕录制怎么打开)

  • 微信运动停用后开启,当天步数有显示吗(微信运动停用后之前的记录还有吗)

    微信运动停用后开启,当天步数有显示吗(微信运动停用后之前的记录还有吗)

  • oppo手机投屏搜索不到设备(oppo手机投屏搜索不到)

    oppo手机投屏搜索不到设备(oppo手机投屏搜索不到)

  • 看点直播可以在电脑上播吗(看点直播可以在哪里看)

    看点直播可以在电脑上播吗(看点直播可以在哪里看)

  • qq群为什么没有群号(QQ群为什么没有群等级)

    qq群为什么没有群号(QQ群为什么没有群等级)

  • win7怎么看电脑是32位还是62位(win7怎么看电脑是多少位)

    win7怎么看电脑是32位还是62位(win7怎么看电脑是多少位)

  • 扫码微信辅助安全吗(微信 扫码 辅助)

    扫码微信辅助安全吗(微信 扫码 辅助)

  • soul几天不上能擦灰(soul多久没有上会蒙灰)

    soul几天不上能擦灰(soul多久没有上会蒙灰)

  • 腾讯会议为什么进不去(腾讯会议为什么打不开摄像头)

    腾讯会议为什么进不去(腾讯会议为什么打不开摄像头)

  • 惠普1522用什么型号的硒鼓(惠普m1522nf打印机怎么样)

    惠普1522用什么型号的硒鼓(惠普m1522nf打印机怎么样)

  • 移动上不了网怎么回事(移动上不了网了)

    移动上不了网怎么回事(移动上不了网了)

  • office是系统软件吗(office属于什么系统)

    office是系统软件吗(office属于什么系统)

  • 苹果xr怎么把屏幕调暗(苹果xr怎么把屏幕锁定)

    苹果xr怎么把屏幕调暗(苹果xr怎么把屏幕锁定)

  • 荣耀8x进水了怎么办(荣耀8x手机进水维修多少钱)

    荣耀8x进水了怎么办(荣耀8x手机进水维修多少钱)

  • 快手怎么知道谁看过我的主页(快手怎么知道谁取关自己)

    快手怎么知道谁看过我的主页(快手怎么知道谁取关自己)

  • 什么叫rgb风扇(什么是rgb风扇)

    什么叫rgb风扇(什么是rgb风扇)

  • 苹果8p充电口防水吗(苹果8p充电口进水了怎么办)

    苹果8p充电口防水吗(苹果8p充电口进水了怎么办)

  • reno2是5g手机吗(reno2z支持5g)

    reno2是5g手机吗(reno2z支持5g)

  • vivo如何查看屏幕使用时间(vivo如何查看屏幕)

    vivo如何查看屏幕使用时间(vivo如何查看屏幕)

  • ipad旁白怎么关闭(ipad旁白在哪里关闭)

    ipad旁白怎么关闭(ipad旁白在哪里关闭)

  • linux CentOS WEB服务器分区方案

    linux CentOS WEB服务器分区方案

  • 前端Vue中实现超炫酷动态背景(全屏背景+自定义banner+登录/注册页)(vue前端开发规范)

    前端Vue中实现超炫酷动态背景(全屏背景+自定义banner+登录/注册页)(vue前端开发规范)

  • 个人所得税退税操作流程
  • 海关缴款书上完税怎么办
  • 跨年取得的发票怎么入账
  • 已付预付款当月应付金额怎么填写?
  • 税务逾期记录怎么消除不了
  • 售后服务企业返利政策
  • 增值税都有哪些科目
  • 哪些依据属于会计凭证
  • 抵扣增值税怎么抵扣
  • 企业抽奖用的奖品有哪些
  • 劳务公司购买设备怎么做账
  • 固定资产累计折旧完了怎么办
  • 借给股东的借款怎么做账
  • 购入货物自用的进项税额转出分录怎么处理
  • 运输业过路费怎么做账
  • 审工资的流程
  • 房产税逾期有滞纳金吗
  • 免税个体户发票税率多少
  • 出租车发票有出租车信息吗
  • 购买的承兑怎么下账
  • 车间机物料消耗属于间接生产费用吗
  • 职工福利费支付范围
  • 调整会计分录是什么
  • php实现批量删除
  • 如何免费获得microsoft
  • 小微企业免征税额度
  • 销售过程会计核算实训过程
  • 企业迁址如何办理手续
  • ssms注释
  • 选择简易计税方法计税的有
  • 将自产的应税消费品用于连续生产应税消费品
  • 事业单位委托业务费的现金流量
  • 企业所得税必须要季度缴纳吗
  • cloa框架
  • 子公司注销母子关系流程
  • flex布局教程实例篇
  • 让我用用你的计算机
  • php curl 封装
  • 出口退税税率差
  • 营业外支出增加的原因
  • 分公司利润怎么结转给总公司需要交税
  • 有销项无进项怎么处理
  • php手机验证码验证
  • sqlserver2008数据库还原
  • 企业所得税季度申报数据怎么来
  • 收到政府补贴如何入账
  • 员工罚款从工资中代扣
  • 委外研发费用如何入账
  • 退休人员返聘签订什么合同
  • 项目投标代理服务方案
  • 已抵扣进项税额转出的会计分录怎么做
  • 公司临时工的车可以买吗
  • 低值易耗工具有哪些
  • 购买原材料保险费分录
  • 销售折扣含义
  • 差旅费的会计处理
  • 包工包料怎么开13个点发票
  • abc类企业的划分
  • 财产租赁合同印花税计税依据
  • 买货品的咨询服务有哪些
  • 发出商品属于存货的什么科目
  • 个体工商户如何缴纳社保
  • 房地产企业会计处理
  • mysql分页效率
  • win10语言栏没有
  • 下载微信
  • win8提升模式
  • linux系统漏洞总结
  • win10任务快速切换
  • win8系统开启摄像头权限
  • win10怎么快一点
  • 简单的安卓程序
  • bat 批处理文件
  • jquery操作html代码
  • 如何把多个文本文档合并成一个且分行不重叠
  • javascript基础入门视频教程
  • js闭包的定义和用途
  • ukey证书初始密码
  • 按照5%的征收率减按1.5%计算应纳税额是什么意思
  • 西安市人力资源和社会保障局关于2020年
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号