/**
*
* @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;
小程序封装网络请求
最新推荐文章于 2024-05-18 14:10:13 发布