vue的token登錄鑒權(quán) vue中Axios的封裝與API接口的管理詳解?
vue中Axios的封裝與API接口的管理詳解?首先,在您創(chuàng)建的public方法的文件中創(chuàng)建一個(gè)新的HttpUtil.js文件文件。以下是總結(jié)HttpUtil.js文件內(nèi)容:VAR Axios=req
vue中Axios的封裝與API接口的管理詳解?
首先,在您創(chuàng)建的public方法的文件中創(chuàng)建一個(gè)新的HttpUtil.js文件文件。以下是總結(jié)HttpUtil.js文件內(nèi)容:VAR Axios=require(“Axios”)//配置項(xiàng)根,例如路徑VAR root=“http://localhost:8090/manage“//Axios請(qǐng)求函數(shù)httpapi(method,URL,params){返回新承諾((resolve,reject)=>{Axios({method:method,URL:URL,數(shù)據(jù):method==“post”;method==“put”?Params:null,Params:Method==“get”| | Method==“delete”?參數(shù):null,baseurl:root,withcredentials:false})。然后((response)=>{解析(response)})。Catch((error)=>{reject(error)})}//返回Vue模板中的調(diào)用接口,導(dǎo)出默認(rèn)值{get:function(URL,parameters){return httpapi(“get”,URL,parameters)},post:function(URL,parameters)},Params){return httpapi(“post”,URL,Params)},put:function(URL,Params){return httpapi(“put”,URL,params)},delete:function(URL,params){return httpapi(“delete”,URL,params)}
胡說八道。每次判斷用戶沒有令牌時(shí),都跳轉(zhuǎn)到“/登錄”,但添加if(到.path==“sign-in”)返回去哪兒(),此方法跳轉(zhuǎn)到“sign-in”。這不是死循環(huán)嗎?路線總是跳到“登錄”,但全球警衛(wèi)判斷它跳到這一點(diǎn),然后再跳。
總之,這是堆棧溢出。遞歸是無限循環(huán)。