建議的小程序版本的axios函數(shù),之所以說(shuō)簡(jiǎn)易,因?yàn)橹皇怯昧顺S玫恼?qǐng)求方法外,然后添加了攔截器而已。 wxhttp命名為wxhttp 具體的請(qǐng)求用法如axios wxhttp#request(config) wxhttp#get(url[,config]) wxhttp#delete(url[,config]) wxhttp#head(url[,config]) wxhttp#options(url[,config]) wxhttp#post(url[,data[,config]]) wxhttp#put(url[,data[,config]]) wxhttp#patch(url[,data[,config]]) 攔截方法:
wxhttp.interceptors.request.use(handleRequest(config),handleError(err)) 注意:handleRequest需要返回處理后的config
wxhttp.interceptors.response.use(handresponse(res)) 注意:handleResponse需要返回處理后的res 例子:
因?yàn)槭褂昧藀romise風(fēng)格,所以可以使用Promise.all方法來(lái)進(jìn)行并發(fā)請(qǐng)求。 |