注意 只能在配置路由对应的父组件路由上面定义
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();
}
},
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。