• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

vue3项目实现登录成功页面回跳

武飞扬头像
hjxhjx-
帮助1

在很多的时候都登录成功都需要回跳,比如  在未登录的情况下将商品加入购物车,会提示先登录.那么登录成功这时就不单止是登录到首页,应该是将页面重新回跳到购物车页面.

登录我这边是放到pinia去管理的

学新通

以下是回跳的解决方案:

  1.  
    actions: {
  2.  
    // 用户名和密码登录
  3.  
    async login(data: { account: string; password: string }) {
  4.  
    const res = await http<Profile>("POST", "/login", data);
  5.  
    console.log("/login", res.data.result);
  6.  
    this.profile = res.data.result
  7.  
    message({ type: "success", text: "登录成功" });
  8.  
    // router.push('/')
  9.  
    // 在vue3项目直接获取router实例即可,vue2当中是this.$router
  10.  
    // 可以通过currentRoute获取路由信息
  11.  
    // 使用 encodeURIComponent() 方法可以对 URI 进行编码
  12.  
    const { target } = router.currentRoute.value.query
  13.  
    if (target) {
  14.  
    // target有可能是string或LocationQueryValue ,target as string是指定类型
  15.  
    router.push(decodeURIComponent(target as string))
  16.  
    } else {
  17.  
    router.push('/')
  18.  
    }
  19.  
     
  20.  
    },
  21.  
    },
学新通

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgaagke
系列文章
更多 icon
同类精品
更多 icon
继续加载