perf: Use and return values directly.

Change array check `instanceof Array` to `Array.isArray`, `instanceof ` doesn't work across iframes.
This commit is contained in:
Edwin Betancourt 2020-07-05 10:14:15 -04:00 committed by GitHub
parent ea60478304
commit 44f4256acf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 11 deletions

View File

@ -1,21 +1,18 @@
import store from '@/store'
/**
* @param {Array} value
* @param {Array} permissionRoles
* @returns {Boolean}
* @example see @/views/permission/directive.vue
*/
export default function checkPermission(value) {
if (value && value instanceof Array && value.length > 0) {
export default function checkPermission(permissionRoles) {
if (permissionRoles && Array.isArray(permissionRoles) && permissionRoles.length > 0) {
const roles = store.getters && store.getters.roles
const permissionRoles = value
const hasPermission = roles.some(role => {
return permissionRoles.includes(role)
})
return hasPermission
} else {
console.error(`need roles! Like v-permission="['admin','editor']"`)
return false
// has permission
return roles.some(role => permissionRoles.includes(role))
}
console.error(`need roles! Like v-permission="['admin','editor']"`)
return false
}