加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vue组件内配置守卫阻止跳转对应的组件

发布时间:2020-12-16 23:29:21 所属栏目:百科 来源:网络整理
导读:注意 只能在配置路由对应的父组件路由上面定义 beforeRouteLeave(to,from,next) { if (to.name == "grapredparack") { //如果要跳转到 grapredparack 这个名字的路由组件上面的时候 如果是列表可以根据在上面循环设置的query.id获取到对应的id this.http.pos
注意 只能在配置路由对应的父组件路由上面定义
  beforeRouteLeave(to,from,next) {
    if (to.name == "grapredparack") {
    //如果要跳转到 grapredparack 这个名字的路由组件上面的时候 如果是列表可以根据在上面循环设置的query.id获取到对应的id
      this.http.post("/api/red/grab",{ redis_id: to.query.id }).then(res => {
        if (res.code == 200) {
          if (res.status == "success") {
            this.$store.commit('userinfo',res.data)
            this.$toasted.success("抢红包成功").goAway(1500);
            setTimeout(() => {
              this.$router.replace({ name: "redpacket" });
            },2000);
          }
          next();
        } else {
          next(false);
        }
      },err => {
        console.log(err)
        next(false)
       this.$toasted.error(err,{ icon: "error" }).goAway(2000);
      });
    } else {
      next();
    }
  },

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读