Vue登陆失效\未登陆跳转页面,在登陆后回到当时页面

场景:

直接提供某个页面路径带了很多参数,然后退回到登陆页面,再登陆就回到该页面。

场景一:

登录过期后回到登陆页;

let num = 0 
service.interceptors.response.use(
    (response) => {
        const res = response.data;

        if (res.code !== 200 && res.code !== '200' && !response.config.headers.apisass) {
            if (res.code == 2010) {
                num = num + 1;
                if (num == 1) {
                    return (window.location.href = window.location.origin + '/#/login?backUrl=' + encodeURIComponent(window.location.href));
                }
            }
            if (res.code === 2011) {
                num = num + 1;
                if (num == 1) {
                    return (window.location.href = window.location.origin + '/#/login?backUrl=' + encodeURIComponent(window.location.href));
                } 如果不判断就会多次拼接 window.location.origin是域名
            }
            if (showMsg) {
                Message({
                    message: res.message || res.msg,
                    type: 'error',
                    duration: 2.5 * 1000
                });
                showMsg = false;
                setTimeout(() => {
                    showMsg = true;
                }, 2000);
            }

            return Promise.reject(res.message || res.msg || 'ErrorError');
        } else {
            return res;
        }
    },
}
场景二:

没有登陆直接去

if (!role && to.path !== '/login' && !token) {
        Vue.prototype.$message.info('请登录');
        next('/login?backUrl=' + encodeURIComponent(window.location.href));
        return;
    }
登录处理:
   if (this.$route.query.backUrl) {
                                    window.location.href = decodeURIComponent(this.$route.query.backUrl);
                                } else {
                                    this.$router.push('/loanDataBoard2');
                                }

最近更新

  1. TCP协议是安全的吗?

    2023-12-11 14:20:03       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-11 14:20:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-11 14:20:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-11 14:20:03       18 阅读

热门阅读

  1. WPF转换器Convert

    2023-12-11 14:20:03       34 阅读
  2. linux中安装miniconda并解决conda:未找到命令的问题

    2023-12-11 14:20:03       44 阅读
  3. mybatis的标签的使用

    2023-12-11 14:20:03       45 阅读
  4. error:move_base_msgs

    2023-12-11 14:20:03       25 阅读
  5. Ubuntu——安装显卡驱动

    2023-12-11 14:20:03       42 阅读
  6. 基于AidLux的工业视觉少样本缺陷检测实战应用

    2023-12-11 14:20:03       36 阅读
  7. ffmpeg常用命令

    2023-12-11 14:20:03       38 阅读
  8. 104. 二叉树的最大深度

    2023-12-11 14:20:03       40 阅读
  9. 将真分数分解为埃及分数

    2023-12-11 14:20:03       39 阅读
  10. 轨道交通虚拟情景实训教学系统演示

    2023-12-11 14:20:03       41 阅读