vue必须登录才能打开页面

2023-04-12  本文已影响0人  我叫杨毅

router文件

function fnCurrentRouteIsPageRoute(route, pageRoutes = []) {
    var temp = [];
    for (var i = 0; i < pageRoutes.length; i++) {
        if (route.path === pageRoutes[i].path) {
            if (route.path === '/kanban' || route.path === '/kanban2') {
                if (localStorage.getItem("token")) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return true;
            }
        }
        if (pageRoutes[i].children && pageRoutes[i].children.length >= 1) {
            temp = temp.concat(pageRoutes[i].children);
        }
    }
    return temp.length >= 1 ? fnCurrentRouteIsPageRoute(route, temp) : false;
}

登录页面, 两个登录成功后添加

 localStorage.setItem("token", res.data.token);

退出登录时清除 localStorage

/**
 * 清除登录信息
 */
export function clearLoginInfo () {
  store.commit('resetStore')
  Cookies.remove('token')
  window.SITE_CONFIG['dynamicMenuRoutesHasAdded'] = false
  // localStorage.clear();
}
上一篇下一篇

猜你喜欢

热点阅读