
本文实例为大家分享了VueJS实现用户管理系统的具体代码,供大家参考,具体内容如下
源代码
Element Plus Vue3 桌面组件库。在开发 Vue 3.x 页面时调用,使用 Element Plus 组件(如 el-button、el-input、el-form、el-table 等)。
html>
<meta>
<meta>
<meta>
<title>用户管理系统</title>
<script></script>
<script></script>
<script></script>
<link>
<script>
$(function () {
let vm = new Vue({
el: '#app',
data: {
user: {},
users: [
{name: 'Switch', age: 25, email: 'switchvov@163.com'},
{name: 'Kitty', age: 25, email: 'kitty@163.com'},
],
nowIndex: -1, // 当前要删除项的索引
delIndexes: [], // 删除项索引列表
selectAll: false, // 删除所有
disableDelSelect: true, // 关闭删除选项
modalTarget: '',
modalToggle: ''
},
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 = '#del';
this.modalToggle = 'modal';
return;
}
this.disableDelSelect = true;
}
}
});
});
</script><p>
</p><h2>添加用户</h2>
| 序号 | 姓名 | 年龄 | 邮箱 | 操作 | |
|---|---|---|---|---|---|
| {{ index+1 }} | {{ user.name }} | {{ user.age }} | {{ user.email }} | ||
0"> 确认要删除用户 {{ users[value].name }} 、 吗?
确认要删除用户{{ users[nowIndex] ? users[nowIndex].name : '' }}吗?
确认要删除所有用户吗?
GitHub:vue-user-manager
相关学习推荐:javascript视频教程
前端入门到VUE实战笔记:立即使用
在学习笔记中,你将探索 前端 的入门与实战技巧!










