[代码优化](v2.6):fix bug

close https://github.com/elunez/eladmin/issues/504
This commit is contained in:
zhengjie
2020-12-12 21:04:41 +08:00
parent bd65391f4d
commit 1526db3d46
17 changed files with 43 additions and 39 deletions

View File

@@ -1,18 +1,19 @@
import store from '@/store'
export default {
inserted(el, binding, vnode) {
inserted(el, binding) {
console.log(el, binding)
const { value } = binding
const roles = store.getters && store.getters.roles
if (value && value instanceof Array && value.length > 0) {
const permissionRoles = value
const hasPermission = roles.some(role => {
return permissionRoles.includes(role)
})
if (!hasPermission) {
el.parentNode && el.parentNode.removeChild(el)
if (value && value instanceof Array) {
if (value.length > 0) {
const permissionRoles = value
const hasPermission = roles.some(role => {
return permissionRoles.includes(role)
})
if (!hasPermission) {
el.parentNode && el.parentNode.removeChild(el)
}
}
} else {
throw new Error(`使用方式: v-permission="['admin','editor']"`)