小程序版结合promise的axios风格ajax请求函数
建议的小程序版本的axios函数,之所以说简易,因为只是用了常用的请求方法外,然后添加了拦截器而已。 wxhttp命名为 具体的请求用法如axios wxhttp#request(config) wxhttp#get(url[,config]) wxhttp#delete(url[,255);'>wxhttp#head(url[,255);'>wxhttp#options(url[,255);'>wxhttp#post(url[,data[,config]]) wxhttp#put(url[,255);'>wxhttp#patch(url[,255);'>拦截方法:
wxhttp.interceptors.request.use(handleRequest(config),handleError(err)) 注意:handleRequest需要返回处理后的config
wxhttp.interceptors.response.use(handresponse(res)) 注意:handleResponse需要返回处理后的res 例子:
因为使用了promise风格,所以可以使用Promise.all方法来进行并发请求。 查看源码 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |