// api接口请求封装 var useApi = (url, data = {}, method = "get") => { var that=this; var requrestTask=wx.request console.log(url); return new Promise((resolve, reject) => { requrestTask ({ url: `${url}`, // 云端正式服 data, method, header: { 'Authorization': 'Bearer '+wx.getStorageSync('token') || '', 'content-type': 'application/json', }, dataType: 'json', // 添加这个配置 success(res) { resolve(res.data) }, fail(err) { // wx.hideLoading() wx.showToast({ title: '加载失败', icon: 'none' }) reject(err) }, complete() { wx.hideLoading(333) wx.hideLoading({ //因为showToast、hideLoading不能同时使用 fail() {} }) } }).onHeadersReceived(res=>{ if(res && res.header && res.header.Authorization) { console.log("获取requestTask",res) wx.setStorageSync("token", res.header.Authorization); } }) }) } module.exports = { useApi, getBanner(data) { console.log(1); return useApi('', data) }, }