美文网首页
微信小程序全局请求封装

微信小程序全局请求封装

作者: 在下高姓 | 来源:发表于2020-06-16 16:47 被阅读0次
GR:function(a,b,c,d){//全局请求
    let data=c;//data数据
    data.token=wx.getStorageSync('token');//默认追加全局需要的参数
    wx.request({
     url: 'https:xxxxxxx'+b,//全局api接口拼接
     method: a,//请求方式
     data: data,//传递是数据
     header: {
       'Content-Type': 'application/x-www-form-urlencoded'
     },
     success: d;//回调
   })
   }
2.调用
   let data={name:777};
    app.GR('GET','XXXXX',data,function(res){
      console.log("请求成功")
    })

相关文章

网友评论

      本文标题:微信小程序全局请求封装

      本文链接:https://www.haomeiwen.com/subject/lderxktx.html