token失效怎么解决?
如果令牌失败,您只能再次登录以获取有效令牌。一般情况下,服务器会为令牌设置一个过期时间,属于正常情况
胡说八道。每次判断用户没有令牌时,都会跳转到“/登录”,但添加if(到.path==“sign-in”)返回去哪儿(),此方法跳转到“sign-in”。这不是死循环吗?路线总是跳到“登录”,但全球警卫判断它跳到这一点,然后再跳。
总之,这是堆栈溢出。递归是无限循环。
Vue利用路由钩子token过期后跳转到登录页的实例?
首先,在您创建的public方法的文件中创建一个新方法HttpUtil.js文件文件。以下是总结HttpUtil.js文件内容:VARAxios=require(“Axios”)//配置项根,例如路径VARroot=“http://localhost:8090/manage“//Axios请求函数httpapi(method,URL,params){返回新承诺((resolve,reject)=>{Axios({method:method,URL:URL,数据:method==“post”;method==“put”?Params:null,Params:Method==“get”||Method==“delete”?参数:null,baseurl:root,withcredentials:false})。然后((response)=>{解析(response)})。Catch((error)=>{reject(error)})}//返回Vue模板中的调用接口,导出默认值{get:function(URL,parameters){returnhttpapi(“get”,URL,parameters)},post:function(URL,parameters)},params){returnhttpapi(“post”,URL,params)},put:function(URL,params){returnhttpapi(“put”,URLparams)},delete:function(url,params){returnhttpApi(“delete”,url,params)}
光影筑梦