登录页获取来源URL,登录成功自动跳转到源页面
使用https://www.cnblogs.com/buglife/p/14402123.html 这篇文章中的JS代码, 用来解析URL携带的 URL参数
所 举例为: 一个详细页面,点击 “收藏” 按钮,校验是否登录,如未登录,跳转到登录页面 且携带来源页面。
详情页 添加方法部分
//VUE添加收藏 方法, 校验登录和跳转
doAddFav(){ axios.get('fav/addFav?rid='+this.routeId) .then(res=>{ if ('用户未登录'==res.data.errorMsg){ this.errMsg = res.data.errorMsg location.href='login.html?soureUrl='+location.href } else if(res.data.flag==true){ this.isFav =true; this.routeDetail.count = res.data.data.count; } })
登录页面: 登录并跳转部分
toLogin(){ if (this.loginUser.username==null || this.loginUser.username==null){ alert("用户名或密码不可为空") } else{ axios.post("user/login",this.loginUser) .then(res=>{ if(res.data.data!=true){
//用户名密码部分 this.errMsg = res.data.errorMsg }else {
// location.href 方法 ,会先校验 sourceUrl是否有值,如果没有 跳转至index.html location.href= getParameter("soureUrl")||'index.html' } }) } }

浙公网安备 33010602011771号