美文网首页
vue必须登录才能打开页面

vue必须登录才能打开页面

作者: 我叫杨毅 | 来源:发表于2023-04-12 13:30 被阅读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();
}

相关文章

网友评论

      本文标题:vue必须登录才能打开页面

      本文链接:https://www.haomeiwen.com/subject/emfoddtx.html