用vue写个系统后台用户管理界面嘛
时间: 2023-11-06 14:04:09 浏览: 62
当然可以!以下是一个示例代码,用 Vue 框架和 Element UI 组件库搭建一个用户管理后台界面:
```
<template>
<div>
<el-table :data="users">
<el-table-column prop="id" label="ID"></el-table-column>
<el-table-column prop="name" label="用户名"></el-table-column>
<el-table-column prop="email" label="邮箱"></el-table-column>
<el-table-column prop="status" label="状态" :formatter="statusFormatter"></el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button type="primary" size="small" @click="editUser(scope.row)">编辑</el-button>
<el-button type="danger" size="small" @click="deleteUser(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-dialog :visible.sync="dialogVisible" title="编辑用户">
<el-form :model="form">
<el-form-item label="用户名" :label-width="formLabelWidth">
<el-input v-model="form.name"></el-input>
</el-form-item>
<el-form-item label="邮箱" :label-width="formLabelWidth">
<el-input v-model="form.email"></el-input>
</el-form-item>
<el-form-item label="状态" :label-width="formLabelWidth">
<el-select v-model="form.status">
<el-option label="正常" value="normal"></el-option>
<el-option label="禁用" value="disabled"></el-option>
</el-select>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="saveUser">保存</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import axios from 'axios'
export default {
data() {
return {
users: [],
dialogVisible: false,
formLabelWidth: '80px',
form: {
id: '',
name: '',
email: '',
status: ''
}
}
},
created() {
this.getUsers()
},
methods: {
getUsers() {
axios.get('/api/users').then(response => {
this.users = response.data
})
},
editUser(user) {
this.form = Object.assign({}, user)
this.dialogVisible = true
},
saveUser() {
axios.put(`/api/users/${this.form.id}`, this.form).then(response => {
this.getUsers()
this.dialogVisible = false
})
},
deleteUser(user) {
if (confirm(`确定要删除用户 ${user.name} 吗?`)) {
axios.delete(`/api/users/${user.id}`).then(response => {
this.getUsers()
})
}
},
statusFormatter(status) {
return status === 'normal' ? '正常' : '禁用'
}
}
}
</script>
```
这是一个非常基础的示例,仅包含了用户列表、编辑和删除功能。你可以根据自己的需求,添加更多功能和页面元素。同时,你也需要根据你的后端 API 接口进行相应的数据请求和处理。
阅读全文