思路:
let url = 'http://localhost:8080';
let requestTotal = 0;
const request = (params) =>{
requestTotal++;
wx.showLoading({
title: '加载中...',
mask: true
})
return new Promise((resolve, reject) =>{
wx.request({
url: url + params.url,
data: params.data || {},
method: params.method || 'GET',
header: {'content-type': 'application/x-www-form-urlencoded;charset=UTF-8'},
success:(result)=>{
resolve(result.data)
},
fail:(error)=>{
console.log(error);
reject(error)
},
complete:()=>{
requestTotal--;
if(requestTotal===0){
wx.hideLoading()
}
}
})
})
}