用vue+elementUI 增删改查写一个 飞航科技管理系统 的用户管理页面
时间: 2024-02-16 17:03:48 浏览: 153
springboot+vue+element增删改查Demo
5星 · 资源好评率100%
好的,我可以为您提供一些思路和代码示例。
首先,您需要在Vue中安装Element UI,并在Vue中注册Element UI组件。
```javascript
// main.js
import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)
```
接下来,您可以创建一个名为UserManagement的组件,并使用Element UI的表格、表单、对话框等组件实现增删改查的功能。
```vue
<template>
<div>
<el-button type="primary" @click="showAddDialog">添加用户</el-button>
<el-table :data="users" style="width: 100%">
<el-table-column prop="name" label="姓名"></el-table-column>
<el-table-column prop="age" label="年龄"></el-table-column>
<el-table-column prop="gender" label="性别"></el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button type="text" @click="handleEdit(scope.row)">编辑</el-button>
<el-button type="text" @click="handleDelete(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-dialog title="添加用户" :visible.sync="addDialogVisible">
<el-form :model="addForm" label-width="80px">
<el-form-item label="姓名">
<el-input v-model="addForm.name"></el-input>
</el-form-item>
<el-form-item label="年龄">
<el-input v-model.number="addForm.age"></el-input>
</el-form-item>
<el-form-item label="性别">
<el-radio-group v-model="addForm.gender">
<el-radio label="male">男</el-radio>
<el-radio label="female">女</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<div slot="footer">
<el-button @click="addDialogVisible = false">取 消</el-button>
<el-button type="primary" @click="handleAdd">确 定</el-button>
</div>
</el-dialog>
<el-dialog title="编辑用户" :visible.sync="editDialogVisible">
<el-form :model="editForm" label-width="80px">
<el-form-item label="姓名">
<el-input v-model="editForm.name"></el-input>
</el-form-item>
<el-form-item label="年龄">
<el-input v-model.number="editForm.age"></el-input>
</el-form-item>
<el-form-item label="性别">
<el-radio-group v-model="editForm.gender">
<el-radio label="male">男</el-radio>
<el-radio label="female">女</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<div slot="footer">
<el-button @click="editDialogVisible = false">取 消</el-button>
<el-button type="primary" @click="handleEditSave">保 存</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
export default {
data() {
return {
users: [
{ id: 1, name: '张三', age: 20, gender: 'male' },
{ id: 2, name: '李四', age: 22, gender: 'female' },
{ id: 3, name: '王五', age: 25, gender: 'male' },
],
addDialogVisible: false,
editDialogVisible: false,
addForm: {
name: '',
age: 0,
gender: 'male',
},
editForm: {
id: 0,
name: '',
age: 0,
gender: 'male',
},
}
},
methods: {
showAddDialog() {
this.addDialogVisible = true
},
handleAdd() {
const id = this.users.length + 1
this.users.push({ ...this.addForm, id })
this.addDialogVisible = false
},
handleEdit(user) {
this.editForm = { ...user }
this.editDialogVisible = true
},
handleEditSave() {
const index = this.users.findIndex(u => u.id === this.editForm.id)
this.users.splice(index, 1, this.editForm)
this.editDialogVisible = false
},
handleDelete(user) {
const index = this.users.findIndex(u => u.id === user.id)
this.users.splice(index, 1)
},
},
}
</script>
```
在这个示例中,我们使用了Element UI的表格组件来展示用户信息,使用了表单组件和对话框组件来实现添加、编辑和删除用户的操作。您可以根据自己的需求进行修改和扩展。
最后,在您的路由文件中注册该组件,即可在浏览器中访问用户管理页面。
```javascript
// router.js
import Vue from 'vue'
import Router from 'vue-router'
import UserManagement from '@/components/UserManagement'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/user-management',
name: 'UserManagement',
component: UserManagement,
},
],
})
```
希望这些代码示例能够帮助到您,祝您开发愉快!
阅读全文