• Vue登录成功后跳转到之前的页面


    很多时候,项目有些页面需要用户进行登录才可以继续进行操作,,登录完之后就需要跳转到用户登录之前想去的那个页面,这个实现比较简单:
    使用axios进行http请求,进行拦截:

    axios.interceptors.response.use(
      res => {
      //对响应数据做些事
      if (res.data.code === -1) { // 这里根据自己接口返回状态进行判断是否需要登录
        router.push({
          path: '/login',
          query:{
            redirect: location.hostname // 防止从外部进来登录
          }
        })
      }
      return res.data;
      },
      error => {
        let errorInfo = error.data.error ? error.data.error.message : error.data;
        return Promise.reject(errorInfo);
      }
    );
    在登录成功后书写逻辑:

    let hostName = this.$route.query.redirect; // 获取域名
    if (hostName === this.$url()) { // 判断如果域名是你项目域名,说明是从本网站内部跳转过来的,
      this.$router.go(-1); // 登录成功后,返回上次进入的页面;
    } else {
      window.open(this.$url()+'/article/news','_self'); // 若不是网站内部跳转过来的,登陆成功后进入网站首页
    }

  • 相关阅读:
    WSGI学习系列WSME
    Murano Weekly Meeting 2015.08.11
    Trace Logging Level
    OpenStack Weekly Rank 2015.08.10
    markdown语法测试集合
    css-定位
    html图像、绝对路径和相对路径,链接
    html块、含样式的标签
    html标题、段落、换行与字符实体
    html概述和基本结构
  • 原文地址:https://www.cnblogs.com/liupengfei13346950447/p/10892174.html
Copyright © 2020-2023  润新知