axios發(fā)送post請(qǐng)求帶參數(shù) 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”,URLparams)},delete:function(url,params){return httpApi(“delete”,url,params)}