解決Ant Design Pro VUE,切換用戶之后,左側菜單不刷新問題


在網上嘗試過很多方法都不可以,包括重置路由,刷新頁面的時候可以,但是使用起來對於用戶不太友好,后來經過努力查找,發現經過深拷貝的OK的,以此記錄

文件路徑 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;
}

  

參考連接:https://www.jianshu.com/p/537f29833db9


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM