微信小程序封装Promise请求
//封装Promise let ajaxTimes = 0; //当存在多个请求时,来控制loading显示与隐藏 let baseUrl = 'https://p.51zuso.com/'; const http = (url,param,method)=>{ ajaxTimes ++; wx.showLoading({ title: '正在加载...', mask:true }); return new Promise((resolve)=>{ wx.request({ url: baseUrl+url, data:param||{}, method:method||"post", success:(res)=>{ resolve(res.data) }, fail:(err)=>{ reject(err); }, complete:()=>{ ajaxTimes --; // 关闭加载图标 if (ajaxTimes === 0) { wx.hideLoading(); } } }) }) }