Loading

vue路由拦截器

router.beforeEach((to, from, next) => {
    if (to.name === "login") {
        next()
        return;
    }
    // 用户是否已登录
    const info = userInfoStore()
    if (!info.userToken) {
        next({"name": "login"})
        return;
    }

    // 用户是否有权限
    let userRole = info.userRole
    let allowRoleList = to.meta.role
    if (allowRoleList.indexOf(userRole) === -1) {
        next({"name": "home"})
        return;
    }
    next()
})
posted @ 2024-09-13 22:55  一只大学生  阅读(1)  评论(0编辑  收藏  举报