1.全局拦截
// response全局拦截 axios.interceptors.response.use( response => { if(response.data.status == 1001){ router.push({ path:'/login' // 状态码不对,跳转登录页面时,需要传一个域名在登录页判断 // 为了防止分享登录页面 query:{redirect:location.hostname} }) } return response; }, error => { return Promise.reject(error.response.data) } )
2.类目初始化接口
// 类目初始化接口 initProductType().then(response =>{ if(response.data.status == 1000){ this.initdata = response.data.productTypeResults }else{ this.$router.push({path:'/login',query:{redirect:location.hostname}}) } })
3.这样在登录页就拿到了上个页面的location.hostname了。然后在登录页判断一下
if(this.$router.query.redirect == location.hostname){ this.$router.go(-1) }else{ this.$router.push({path:'/index'}) }