From 44f4256acf9abe53fc789513d3441329d0884630 Mon Sep 17 00:00:00 2001 From: Edwin Betancourt Date: Sun, 5 Jul 2020 10:14:15 -0400 Subject: [PATCH 1/2] perf: Use and return values directly. Change array check `instanceof Array` to `Array.isArray`, `instanceof ` doesn't work across iframes. --- src/utils/permission.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/utils/permission.js b/src/utils/permission.js index 8e2bbada..53d27ac8 100644 --- a/src/utils/permission.js +++ b/src/utils/permission.js @@ -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 } From a61e652b52aef5ebc9504a769af8be202da4bd40 Mon Sep 17 00:00:00 2001 From: Edwin Betancourt Date: Thu, 1 Oct 2020 08:38:12 -0400 Subject: [PATCH 2/2] Update request.js --- src/utils/request.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils/request.js b/src/utils/request.js index 2fb95ac0..de2131bf 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -67,9 +67,8 @@ service.interceptors.response.use( }) } return Promise.reject(new Error(res.message || 'Error')) - } else { - return res } + return res }, error => { console.log('err' + error) // for debug