首页 > web前端 > js教程 > 正文

Bootstrap与Vue操作用户信息的添加与删除

php中世界最好的语言
发布: 2018-04-16 17:35:13
原创
1945人浏览过

这次给大家带来Bootstrap与Vue操作用户信息的添加与删除,Bootstrap与Vue操作用户信息添加与删除的注意事项有哪些,下面就是实战案例,一起来看一下。

<!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>
  <!-- 模态框 -->
  <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">确认删除?</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)">确认</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>
登录后复制

实现效果如下,因为只是简单的实现编辑删除的功能,因此密码就直接显示在表格中,没有进行加密显示

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

Angular操作表单增删改查的验证功能

源生JS怎样实现文件异步上传

以上就是Bootstrap与Vue操作用户信息的添加与删除的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号