小程序request请求包装

微信小程序,微信公开课,小程序request请求包装 微信公开课

如何看待微信公开课小程序热门讨论「小程序request请求包装」
摘要:小程序request请求包装
展开://请求包装varmyrequestfunction(requestobj){if((!requestobj.header||requestobj.header.authnull)){console.log(没有请求权限代码,默认无权限要求请求);}else{if((requestobj.header.auth1||requestobj.header.auth2)!token){//需要登录且未登录console.log(需要登录且未登录);login(myrequest,requestobj);//调用登录,登录完成后回调请求return;}elseif(requestobj.header.auth2){//需绑定手机号且未绑定手机号console.log(需认证且未认证);bind();//调用绑定手机号弹出框return;}else{console.log(通过验证,准备向服务器发送请求);}}wx.request({url:requestobj.url,data:requestobj.data,header:Object.assign({contenttype:application/json,token:token},requestobj.header),method:requestobj.method!null?requestobj.method:GET,success:function(res){console.log(res.data);if(res.statusCode200||res.statusCode304){if(res.data.errcode0){typeofrequestobj.successfunctionrequestobj.success(res)}else{wx.showToast({title:res.data.errmsg,image:/images/icon/error.png,duration:3000})}}else{wx.showToast({title:服务器响应失败,image:/images/icon/error.png,duration:3000})}},fail:function(res){wx.showToast({title:请求失败,image:/images/icon/error.png,duration:3000})typeofrequestobj.failfunctionrequestobj.fail(res)},complete:function(){typeofrequestobj.completefunctionrequestobj.complete()}})}//登录varloginfunction(cb,requestobj){if(token){console.log(已登录);}else{console.log(调用登录);wx.login({success:function(res){if(res.code){console.log(res.code);myrequest({url:requestUrl.loginUrl,data:{code:res.code},method:POST,success:function(res){tokenres.data.data.openid;console.log(token);typeofcbfunctioncb(requestobj)}})}else{console.log(获取用户登录态失败!+res.errMsg)}}})}}//一般请求myrequest({url:requestUrl.indexRequestUrl,data:{showAgent:1},header:{//0、直接请求1、需登录请求2.需登录且绑定手机后请求auth:1},success:function(res){console.log(私success);that.setData({Carousel:res.data.data.Carousel,Menu:res.data.data.Menu})}});了解更多

「小程序request请求包装」热门讨论订阅

微信小程序,微信公开课,小程序request请求包装
订阅小程序

方法1:微信扫描微信公开课小程序码即可订阅热门讨论「小程序request请求包装」

方法2:微信搜索微信公开课小程序名称进入,即可订阅热门讨论「小程序request请求包装」

方法3:微信网页访问即速商店,长按识别微信公开课小程序码即可订阅热门讨论「小程序request请求包装」

微信公开课小程序热门讨论「小程序request请求包装」由微信公开课原创摘录于微信小程序商店shop.jisuapp.cn,转载请注明出处。

微信公开课热门讨论「小程序request请求包装」由微信公开课开发者向微信用户提供,并对本服务内容、数据资料及其运营行为等真实性、合法性及有效性承担全部责任。