You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{
path: '/permission',
component: Layout,
redirect: '/permission/index',
alwaysShow: true, // will always show the root menu
meta: {
title: 'permission',
icon: 'lock',
roles: ['admin', 'editor'] // you can set roles in root nav
},
children: [{
path: 'page',
component: () => import('@/views/permission/page'),
name: 'pagePermission',
meta: {
title: 'pagePermission',
roles: ['admin'] // or you can only set roles in sub nav
}
}, {
path: 'directive',
component: () => import('@/views/permission/directive'),
name: 'directivePermission',
meta: {
title: 'directivePermission'
// if do not set roles, means: this page does not require permission
}
}]
}]
权限管理
Vue权限管理可以分为4个方面:
接口权限
接口请求验证
token
,当token
无效时,接口无权限访问,页面重定向跳转至登录页登录。路由权限
用户登录,有权限访问的路由,即为路由权限控制。
方案1:
初始化挂载全部的路由,路由配置再添加
roles
有权访问的角色。方案2:
初始化先挂载不需要权限控制的路由,比如登录页、404等错误页。登录后,获取用户的权限信息,然后筛选有权限访问的路由,在全局路由守卫里调用
addRoutes
动态添加路由即可。菜单权限
方案1:
菜单与路由分离,菜单由后端接口返回。
方案2:
菜单和路由都由后端接口返回。
按钮权限控制如何做?
方案一:v-if判断:用户权限
role
和路由表里的meta.btnPermissions
匹配判断。方案二:自定义指令
v-permission
1)定义权限鉴定指令
2)按钮引用
v-permission
指令3)优化:
接口返回的权限节点 Array 可以使用 Set 存储优化。
The text was updated successfully, but these errors were encountered: