Fe-interview: [vue] vue要做权限管理该怎么做?如果控制到按钮级别的权限怎么做?

Created on 20 Jun 2019  ·  3Comments  ·  Source: haizlin/fe-interview

[vue] vue要做权限管理该怎么做?如果控制到按钮级别的权限怎么做?

vue

Most helpful comment

按钮级别的权限
https://panjiachen.github.io/vue-element-admin-site/zh/guide/essentials/permission.html#%E6%8C%87%E4%BB%A4%E6%9D%83%E9%99%90

All 3 comments

可以通过指令去做
Vue.directive('hasPermission', {
bind(el, binding, vnode) {
const permissions = vnode.context.$store.state.account.permissions
if (binding.value === '') return
const value = binding.value.split(',')
let flag = true
for (const v of value) {
if (!permissions.includes(v)) {
flag = false
}
}
if (!flag) {
if (!el.parentNode) {
el.style.display = 'none'
} else {
el.parentNode.removeChild(el)
}
}
}
}

按钮级别的权限
https://panjiachen.github.io/vue-element-admin-site/zh/guide/essentials/permission.html#%E6%8C%87%E4%BB%A4%E6%9D%83%E9%99%90

如果权限角色是动态的,那么要为每个按钮做标识,根据这个标识去查哪些角色拥有该权限,再根据登录人的权限角色进行显示与否。

Was this page helpful?
0 / 5 - 0 ratings