/** * * @param {string 请求的方式 get/post} method * @param {发送的参数} params * @param {请求的接口地址} url * @param {信息弹窗交互数据} message * @param {成功的回调函数} callback * @param {失败的回调函数} error */
function http(method,params,url,message,callback,error){
if(message){
wx.showLoading({
title: message,
})
}
// 网络请求
wx.request({
//method:'get/post',
url: url,
data:params,
success:res=>{
console.log(res.data);
if(res.data.status==200){
wx.showToast({
title: '数据加载完毕',
})
//返回数据
callback(res.data);
}else{
console.log("没有数据");
}
},
fail:err=>{
error("请求失败");
},
complete:function(){
wx.hideLoading()
}
})
}
module.exports=http;
还没有评论,来说两句吧...