文件路径 src/store/modules/permission.js
// 从lodash中引入深拷贝
import cloneDeep from "lodash.clonedeep";
//修改此函数
function filterAsyncRouter(routerMap, roles) {
// 增加此行是因为如果不深拷贝,会更改原路由表,当切换用户时,会出现用户该有的菜单无法显示
let asyncRouterMap = cloneDeep(routerMap);
const accessedRouters = asyncRouterMap.filter(route => {
if (hasPermission(roles.permissionList, route)) {
if (route.children && route.children.length) {
route.children = filterAsyncRouter(route.children, roles);
}
return true;
}
return false;
});
return accessedRouters;
}
网友评论