search
HomeWeb Front-endJS TutorialVueJS method to implement user management system
VueJS method to implement user management systemJul 17, 2020 pm 05:35 PM
vueUser Management

VueJS method to implement user management system

The example in this article shares the specific code of VueJS to implement the user management system for your reference. The specific content is as follows

Source code

<!doctype html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport"
  content="width=device-width, user-scalable=no,
  initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
 <meta http-equiv="X-UA-Compatible" content="ie=edge">
 <title>用户管理系统</title>
 <script src="js/jquery.js"></script>
 <script src="js/bootstrap.js"></script>
 <script src="js/vue.js"></script>
 <link rel="stylesheet" href="css/bootstrap.css" type="text/css">
 <script>
 $(function () {
  let vm = new Vue({
  el: &#39;#app&#39;,
  data: {
   user: {},
   users: [
   {name: &#39;Switch&#39;, age: 25, email: &#39;switchvov@163.com&#39;},
   {name: &#39;Kitty&#39;, age: 25, email: &#39;kitty@163.com&#39;},
   ],
   nowIndex: -1, // 当前要删除项的索引
   delIndexes: [], // 删除项索引列表
   selectAll: false, // 删除所有
   disableDelSelect: true, // 关闭删除选项
   modalTarget: &#39;&#39;,
   modalToggle: &#39;&#39;
  },
  methods: {
   addUser: function () {
   this.users.push(this.user);
   this.user = {};
   },
   deleteUser: function () {
   if (this.delIndexes.length > 0) {
    // 从大到小排序,不排序则会出现删除错乱
    this.delIndexes.sort(function (a, b) {
    return b - a;
    });
    for (let i = 0; i < this.delIndexes.length; i++) {
    this.users.splice(this.delIndexes[i], 1);
    }
    this.delIndexes = [];
    this.selectAll = false;
    return;
   }
   if (this.nowIndex === -1) {
    this.users = [];
    return;
   }
   this.users.splice(this.nowIndex, 1);
   },
   toggleAll: function () {
   if (this.selectAll) {
    let length = this.users.length;
    this.delIndexes = [];
    for (let i = 0; i < length; i++) {
    this.delIndexes.push(i);
    }
    return;
   }
   this.delIndexes = [];
   }
  },
  watch: {
   delIndexes: function () {
   if (this.delIndexes.length > 0) {
    this.disableDelSelect = false;
    this.modalTarget = &#39;#del&#39;;
    this.modalToggle = &#39;modal&#39;;
    return;
   }
   this.disableDelSelect = true;
   }
  }
  });
 });
 </script>
</head>
<body>
<p id="app" class="container">
 <h2 id="添加用户">添加用户</h2>
 <form class="form-horizontal">
 <p class="form-group">
  <label for="name" class="control-label col-sm-2 col-sm-offset-2">姓 名:</label>
  <p class="col-sm-6">
  <input type="text" class="form-control" id="name" v-model="user.name" placeholder="请输入姓名">
  </p>
 </p>
 <p class="form-group">
  <label for="age" class="control-label col-sm-2 col-sm-offset-2">年 龄:</label>
  <p class="col-sm-6">
  <input type="text" class="form-control" id="age" v-model="user.age" placeholder="请输入年龄">
  </p>
 </p>
 <p class="form-group">
  <label for="email" class="control-label col-sm-2 col-sm-offset-2">邮 箱:</label>
  <p class="col-sm-6">
  <input type="text" class="form-control" id="email" v-model="user.email" placeholder="请输入邮箱">
  </p>
 </p>
 <p class="form-group text-center">
  <input type="button" value="添 加" class="btn btn-primary" @click="addUser">
  <input type="reset" value="重 置" class="btn btn-primary">
 </p>
 </form>
 <br/>
 <table class="table table-bordered table-hover">
 <caption class="h3 text-center text-info">用户列表</caption>
 <thead>
 <tr>
  <th class="text-center">
  <input type="checkbox" @click="toggleAll" v-model="selectAll">
  </th>
  <th class="text-center">序号</th>
  <th class="text-center">姓名</th>
  <th class="text-center">年龄</th>
  <th class="text-center">邮箱</th>
  <th class="text-center">操作</th>
 </tr>
 </thead>
 <tbody>
 <tr v-for="(user, index) in users" class="text-center">
  <td>
  <input type="checkbox" :value="index" :id="index" v-model="delIndexes" @click="selectAll = false">
  </td>
  <td>{{ index+1 }}</td>
  <td>{{ user.name }}</td>
  <td>{{ user.age }}</td>
  <td>{{ user.email }}</td>
  <td>
  <button class="btn btn-danger" data-toggle="modal" data-target="#del" @click="nowIndex = index;delIndexes=[]">
   删除
  </button>
  </td>
 </tr>
 <tr>
  <td colspan="6" class="text-right">
  <button class="btn btn-danger" data-toggle="modal" data-target="#del" @click="nowIndex = -1;delIndexes=[]">
   删除所有
  </button>
  <button class="btn btn-danger" :data-toggle="modalToggle" :data-target="modalTarget"
   :class="{disabled:disableDelSelect}">
   删除选中
  </button>
  </td>
 </tr>
 </tbody>
 </table>

 <!-- 弹出框 -->
 <p class="modal" id="del">
 <p class="modal-dialog">
  <p class="modal-content">
  <p class="modal-header">
   <button class="close" data-dismiss="modal">
   <span>&times;</span>
   </button>
   <h4 class="modal-title" v-show="delIndexes.length > 0">
   确认要删除用户
   <span v-for="(value, index) in delIndexes">
    {{ users[value].name }}
    <span v-if="index < delIndexes.length - 1">、</span>
   </span>
   吗?
   </h4>
   <h4 class="modal-title" v-show="delIndexes.length === 0 && nowIndex !== -1">
   确认要删除用户{{ users[nowIndex] ? users[nowIndex].name : &#39;&#39; }}吗?
   </h4>
   <h4 class="modal-title" v-show="delIndexes.length === 0 && nowIndex === -1">
   确认要删除所有用户吗?
   </h4>
  </p>
  <p class="modal-body text-center">
   <button class="btn btn-primary" data-dismiss="modal">取消</button>
   <button class="btn btn-primary" data-dismiss="modal" @click="deleteUser">确认</button>
  </p>
  </p>
 </p>
 </p>
</p>
</body>
</html>

GitHub :vue-user-manager

Related learning recommendations: javascript video tutorial

The above is the detailed content of VueJS method to implement user management system. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:jb51. If there is any infringement, please contact admin@php.cn delete
Vue常见面试题汇总(附答案解析)Vue常见面试题汇总(附答案解析)Apr 08, 2021 pm 07:54 PM

本篇文章给大家分享一些Vue面试题(附答案解析)。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

5 款适合国内使用的 Vue 移动端 UI 组件库5 款适合国内使用的 Vue 移动端 UI 组件库May 05, 2022 pm 09:11 PM

本篇文章给大家分享5 款适合国内使用的 Vue 移动端 UI 组件库,希望对大家有所帮助!

vue中props可以传递函数吗vue中props可以传递函数吗Jun 16, 2022 am 10:39 AM

vue中props可以传递函数;vue中可以将字符串、数组、数字和对象作为props传递,props主要用于组件的传值,目的为了接收外面传过来的数据,语法为“export default {methods: {myFunction() {// ...}}};”。

手把手带你利用vue3.x绘制流程图手把手带你利用vue3.x绘制流程图Jun 08, 2022 am 11:57 AM

利用vue3.x怎么绘制流程图?下面本篇文章给大家分享基于 vue3.x 的流程图绘制方法,希望对大家有所帮助!

如何覆盖组件库样式?React和Vue项目的解决方法浅析如何覆盖组件库样式?React和Vue项目的解决方法浅析May 16, 2022 am 11:15 AM

如何覆盖组件库样式?下面本篇文章给大家介绍一下React和Vue项目中优雅地覆盖组件库样式的方法,希望对大家有所帮助!

聊聊vue指令中的修饰符,常用事件修饰符总结聊聊vue指令中的修饰符,常用事件修饰符总结May 09, 2022 am 11:07 AM

本篇文章带大家聊聊vue指令中的修饰符,对比一下vue中的指令修饰符和dom事件中的event对象,介绍一下常用的事件修饰符,希望对大家有所帮助!

通过9个Vue3 组件库,看看聊前端的流行趋势!通过9个Vue3 组件库,看看聊前端的流行趋势!May 07, 2022 am 11:31 AM

本篇文章给大家分享9个开源的 Vue3 组件库,通过它们聊聊发现的前端的流行趋势,希望对大家有所帮助!

react与vue的虚拟dom有什么区别react与vue的虚拟dom有什么区别Apr 22, 2022 am 11:11 AM

react与vue的虚拟dom没有区别;react和vue的虚拟dom都是用js对象来模拟真实DOM,用虚拟DOM的diff来最小化更新真实DOM,可以减小不必要的性能损耗,按颗粒度分为不同的类型比较同层级dom节点,进行增、删、移的操作。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software