VUE项目-次日html
01-反馈vue
姓名 意见或建议
*** 1.从谏如流而不是在每次看到反馈意见以后先推脱,再勉强接受,你们写出来的建议只是为了更方便快速的学习,别无他意(更不涉及怪不怪谁的问); 2.保证笔记的完整性和条理性应该算是最基本要完成的工做,在互动性比较高的工做中应该多考虑怎么利他; 3.待续 *** 单页面应用开发能够移动端吗???单页面主要作些什么项目啊??
*** 刚哥
*** 老师,为何会出现莫名其妙丢包的状况呢
*** 老师, 爱你 么么哒
*** 但愿老师注释可以更详细些~mysql
02-回顾ios
03-首页-动态导航菜单git
视图区:vue-router
<!--一级菜单-->
<!-- 注意: 一级菜单 index 和 二级菜单 index 是有从属关系的 -->
<!-- 一级菜单的索引 id 二级菜单的索引 item.id-lastItem.id -->
<el-submenu :index="item.id" v-for="(item,i) in menus" :key="item.id">
<template slot="title">
<i class="el-icon-location"></i>
<span>{{item.authName}}</span>
</template>
<!--二级菜单-->
<el-menu-item :index="item.id+'-'+lastItem.id" v-for="lastItem in item.children" :key="lastItem.id">
{{lastItem.authName}}
</el-menu-item>
</el-submenu>
复制代码
js区域:sql
async getData () {
// 获取数据
const {data: {data, meta}} = await this.$http.get('menus')
// 判断获取是否成功 注意:添加操做 201 其余操做 200
if (meta.status !== 200) return this.$message.error('获取菜单失败')
// 已经成功 修改data中的菜单数据
this.menus = data
// 更新视图 前提是视图用了该数据
// 去视图 用户指令 渲染出来
}
复制代码
04-首页-导航菜单细节express
<i class="el-icon-menu"></i>
<span>{{lastItem.authName}}</span>
复制代码
<span class="iconfont icon-user-fill"></span>
<span class="iconfont icon-cog"></span>
<span class="iconfont icon-shoppingcart"></span>
<span class="iconfont icon-file"></span>
<span class="iconfont icon-chart-area"></span>
复制代码
05-首页-欢迎组件element-ui
路由:axios
// 二级路由配置 将会在home组件下使用
children: [
{path: '/welcome', name: 'welcome', component: Welcome}
]
复制代码
组件:
<template>
<div class="welcome_container">
<h3>欢迎来到品优购后台关系系统</h3>
<img src="../assets/images/welcome.jpg" alt="">
</div>
</template>
<script>
export default {
name: 'Welcome'
}
</script>
<style scoped>
.welcome_container{
text-align: center;
}
</style>
复制代码
指定视图显示的位置:
<el-main class="home_main">
<router-view></router-view>
</el-main>
复制代码
当你到首页时 默认显示的是欢迎组件
redirect: '/welcome',
复制代码
为了演示 实现退出
// Home.vue
logout () {
// 思考: 清除token 就是退出 可是跳转登陆页
sessionStorage.removeItem('token')
this.$router.push('/login')
}
复制代码
06-用户管理-路由和组件骨架
配置路由:
{path: '/users', name: 'users', component: Users}
复制代码
组件骨架:
<template>
<div class="users_container">
用户列表
</div>
</template>
<script>
export default {
name: 'Users'
}
</script>
<style scoped>
</style>
复制代码
新建分支切切换: git checkout -b users
07-用户管理-用户列表
08-用户管理-用户添加
分析dialog组件的结构,修改为咱们须要的结构
点击添加 显示对话框
<el-button type="primary" @click="dialogFormVisible = true" plain>添加用户
指定数据
// 标识当前对话框是否显示 dialogFormVisible: false, // 添加用户表单对象数据 addForm: { username: '', password: '', email: '', mobile: '' }
校验表单
提交数据 addSubmit () { // 输入的时候进行数据的验证 // 请求前点击提交的时候 还要验证一次 this.http.post('users', this.addForm) if (meta.status !== 201) return this.$message.error('添加失败') // 添加成功后 this.dialogFormVisible = false // 更新列表 this.getData() } }) },
添加表单的细节
showDialogForm () { // 注意: 只有先渲染 找到dom // 显示添加对话框 this.dialogFormVisible = true // 重置表单 内容 验证 this.$refs.addForm.resetFields() }
09-用户管理-用户删除
改列表的按钮这一列 改为能够传数据的
<template slot-scope="scope">
<el-button-group>
<el-button icon="el-icon-edit" round></el-button>
<el-button icon="el-icon-delete" @click="delUsers(scope.row.id)" round></el-button>
<el-button icon="el-icon-setting" round></el-button>
</el-button-group>
</template>
复制代码
定义一个删除函数
delUsers (id) {
// 删除用户 ID
this.$confirm('是否删除该数据?', '舒适提示', {
confirmButtonText: '肯定',
cancelButtonText: '取消',
type: 'warning'
}).then(async () => {
// 点击了确认 发请求
const {data: {meta}} = await this.$http.delete(`users/${id}`)
if (meta.status !== 200) return this.$message.error('删除失败')
this.$message.success('删除成功')
this.getData()
}).catch(() => {})
}
复制代码
10-用户管理-用户编辑
11-用户管理-修改状态
绑定值修改事件 change
<el-switch
@change="updateState(scope.row.id,scope.row.mg_state)"
v-model="scope.row.mg_state"
active-color="#13ce66"
inactive-color="#ccc">
</el-switch>
复制代码
请求后台
async updateState (id, newState) {
// id 用户的ID newState 已改变的状态
// console.log(id, newState)
const {data: {meta}} = await this.$http.put(`users/${id}/state/${newState}`)
if (meta.status !== 200) return this.$message.error('修改状态失败')
this.$message.success('修改状态成功')
this.getData()
}
复制代码
12-用户管理-分配角色
第一步:画分配角色的对话框
<!--分配角色-->
<el-dialog width="400px" title="分配角色" :visible.sync="roleDialogFormVisible">
<el-form label-width="100px" autocomplete="off">
<el-form-item label="当前用户:">
admin
</el-form-item>
<el-form-item label="当前用户:">
超级管理员
</el-form-item>
<el-form-item label="分配角色:">
<el-select v-model="roleValue" placeholder="请选择">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false">取 消</el-button>
<el-button type="primary" @click="addSubmit()">确 定</el-button>
</div>
</el-dialog>
复制代码
第二步:动态渲染下拉框 角色
<el-select v-model="roleValue" placeholder="请选择">
<el-option
v-for="item in options"
:key="item.id"
:label="item.roleName"
:value="item.id">
</el-option>
</el-select>
复制代码
数据:
async showRoleDialogFormVisible () {
// 打开对话框
this.roleDialogFormVisible = true
// 渲染下拉菜单
const {data: {data, meta}} = await this.$http.get('roles')
if (meta.status !== 200) return this.$message.error('获取角色失败')
this.options = data
console.log(data)
}
复制代码
第三步:获取当前用户的信息在对话框显示
<el-form-item label="当前用户:">
{{roleUserName}}
</el-form-item>
<el-form-item label="当前用户:">
{{roleUserRoleName}}
// 当前用户的 用户名
roleUserName: '',
// 当前用户的 角色
roleUserRoleName: '',
this.roleUserName = row.username
this.roleUserRoleName = row.role_name
复制代码
第四步:提交角色
<el-button type="primary" @click="changeRole()">确 定</el-button>
async changeRole () {
const {data: {meta}} = await this.$http.put(`users/${this.roleUserId}/role`, {
rid: this.roleValue
})
if (meta.status !== 200) return this.$message.error('分配角色失败')
this.$message.success('分配角色成功')
this.roleDialogFormVisible = false
this.getData()
}
复制代码