vue|vue router权限管理实现不同角色显示不同路由
目录
- 思路:
- 主要逻辑代码
- 全部页面代码
思路:
- login页面登录时 加上角色的标记,存储到本地缓存(localstorage)
- 路由js文件,meta属性加个是否可见(visiable true或false)
- home 基本导航栏页面逻辑,首先 可以获得到 所有一级菜单和角色标记
- for 循环一级菜单
- 找出角色 所在的 角色数组(判断某个值在不在 数组中)
- 然后 所在的数组 visiable 改为true ,其他的改为false
主要逻辑代码 1-登录页面
文章图片
2- 路由页面
文章图片
3- home 菜单栏公用页面
文章图片
文章图片
全部页面代码 1. 登录页面
登录
2. 路由js文件
import Vue from 'vue'import Router from 'vue-router'import HelloWorld from '@/components/HelloWorld'Vue.use(Router)export default new Router({routes: [//一级路由{path: "/login",name: "Login",meta: { requireAuth: false },component: require("@/view/Login").default,},// 提供页面框架{path: "/",name: "Home",meta: { requireAuth: true },component: require("@/view/Home").default,redirect: "/index",children:[{path: '/HelloWorld',name: 'HelloWorld',component: HelloWorld,meta: {requireAuth: false,visiable: true,roles: ['superadmin','admin','user']}},{path: '/SuperAdmin',name: 'SuperAdmin',component: () => import("@/view/SuperAdmin.vue"),meta: {requireAuth: false,visiable: true, roles: ['superadmin']}},{path: '/Admin',name: 'Admin',component: () => import("@/view/Admin.vue"),meta: {requireAuth: false, visiable: true, roles: ['admin']}},{path: '/User',name: 'User',component: () => import("@/view/User.vue"),meta: {requireAuth: false,visiable: true,roles: ['user']}},],}]})
3. home公用菜单栏页面(ui框架 是ant design of vue)
项目名
{{ item.name }}
{{ child.name }}
{{ item.name }}(collapsed = !collapsed)"/>退出登录/* 退出登录 */.headerflex {display: flex; align-items: center; justify-content: space-between; }.rights {padding: 0 24px; }#components-layout-demo-custom-trigger .trigger {font-size: 18px; height: 60px !important; line-height: 60px !important; padding: 0 24px; cursor: pointer; transition: color 0.3s; }#components-layout-demo-custom-trigger .trigger:hover {color: #1890ff; }#components-layout-demo-custom-trigger .logo {height: 52px; margin: 16px 16px 10px; display: flex; align-items: center; }#components-layout-demo-custom-trigger .logo img {width: 30px; height: 30px; margin-right: 10px; }#components-layout-demo-custom-trigger .logo p {color: #fff; margin-bottom: 0; font-size: 16px; font-weight: 700; }.ciclebox {position: relative; }.ciclered {position: absolute; right: 0; top: 50%; transform: translateY(-50%); display: inline-block; width: 15px; height: 15px; border-radius: 50%; text-align: center; line-height: 15px; background-color: #e72c0b; color: #fff; font-size: 12px; }.icon {padding-left: 10px; }.app-header-right .ant-menu-horizontal {line-height: 60px !important; }.app-user-avatar img{width:20px; height:20px; }* p {margin-bottom: 0 !important; }* ul,* li {padding: 0; margin: 0; list-style: none; }.ant-card-body {padding-top: 20px; }.change-inline {display: inline-block; }.container .page-header {height: 84px; padding: 16px; background-color: #fff; }.container .page-header h3 {font-size: 20px; padding-top: 8px; font-weight: 600; }.container .claear-top-height {height: auto !important; }.container .infomation-box-top {margin-top: 10px; }.container .infomation-box-top h3 {font-weight: 600; margin-bottom: 14px; }.container .infomation-box-top p {margin-bottom: 0; line-height: 38px; color: #4b4b4b; }.container .infomation-box-top .status-identity {height: 108px; display: flex; align-items: flex-end; justify-content: center; }.container .infomation-box-top .status-identity .type-title {color: #666666; font-weight: 600; }.container .infomation-box-top .status-identity p {white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }.container .infomation-box-top .status-identity .set-width {width: 80%; }.container .infomation-box-top .status-identity .set-width .add-right-border {height: 76px; border-right: 2px solid #F4F4F4; }.container .infomation-box-top .status-identity .set-width .add-right-border span {font-weight: 600; }.container .infomation-box-top .status-identity .set-width .add-right-border .money-edit {display: flex; align-items: center; justify-content: space-between; }.container .infomation-box-top .status-identity .set-width .add-right-border .anticon {margin-right: 10% !important; }.container .infomation-box-top .status-identity .set-width .add-right-border .edit-icon-color {color: #2B85E4; }.container .set-flex-end {display: flex; justify-content: flex-end; margin-bottom: 16px; }.container .set-flex-end .button-group {display: flex; align-items: center; }.container .set-flex-end .button-group .search {margin-right: 16px; }.container .table-style .recommender {text-decoration: underline; color: #2B85E4; }.container .table-style .table-role {margin-bottom: 0; cursor: default; }.container .table-style .role-r {color: #19BE6B; }.container .table-style .role-s {color: #FF9900; }.container .table-style .role-t {color: #2B85E4; }.container .table-style .role-w {color: #F56C6C; }.container .table-style .role-c {color: #8b8b8b; }.container .table-style .text-detail {color: #409EFF; padding: auto 10px !important; }.container .table-style .addleft-padding {padding-left: 10px; }.container .table-style .order-to {color: #409EFF; padding-left: 10px !important; }.container .table-style .text-stop {color: #F56C6C; padding-left: 10px !important; }.container .table-style .text-stopis {color: #2fc25b; padding-left: 10px !important; }.container .pagination-margin {margin-top: 25px; display: flex; justify-content: flex-end; }.container .ant-tabs-bar {padding-left: 30px; background: #fff; font-weight: 600; margin: 0 0 26px !important; }.container .ant-tabs-nav {font-size: 15px !important; }.container .ant-tabs-nav .ant-tabs-tab {margin-right: 0 !important; padding-bottom: 20px; }.container .tab-pane-set {padding: 0 2%; }.container .ant-card-head-title {padding: 0px; min-height: 44px !important; line-height: 44px; font-size: 15px; font-weight: 600; color: #6b6b6b; }.padbox {margin-left: 10px; }.appoint {background: #e72c0b; color: #e72c0b !important; }.wait {background: #ff9900; color: #ff9900 !important; }.pass {background: #2fc25b; color: #2fc25b; }.success {background: #409eff; color: #409eff !important; }.cancel {background: #8b8b8b; color: #8b8b8b; }.red {color: #e72c0b !important; }.appoint_cl {color: #e72c0b !important; }.wait_cl {color: #ff9900 !important; }.pass_cl {color: #2fc25b !important; }.success_cl {color: #409eff !important; }.cancel_cl {color: #8b8b8b !important; }.clear-bg {background: none !important; }
项目目录
文章图片
【vue|vue router权限管理实现不同角色显示不同路由】 到此这篇关于vue router权限管理实现不同角色显示不同路由的文章就介绍到这了,更多相关vue router 不同角色显示不同路由内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
推荐阅读
- Vue源码学习之响应式是如何实现的
- vue-devtools|vue-devtools 开发工具插件之支持vue3 chrome 浏览器插件
- vue实现四级导航及验证码的方法实例
- vue-cli3+echarts实现渐变色仪表盘组件封装
- Vue中Axios中取消请求及阻止重复请求的方法
- vue+js点击箭头实现图片切换
- Vue使用Proxy代理后仍无法生效的解决
- Vue中使用js制作进度条式数据对比动画
- Vue实现鼠标悬浮切换图片src
- vue|记事本(本地应用,基于vue.js)