//在app.js中
App({
onLaunch: function () {
// this.globalData.userId = wx.getStorageSync("wxUserId");
// this.globalData.token = wx.getStorageSync("wxToken");
},
request({ url, data, method, success, fail, complete }) {
wx.request({
url: this.globalData.baseUrl + url,
data: data,
method: method || "POST",
header: {
Authorization: '',
},
success: (res) => {
if (res.statusCode == 200) {
success(res.data);
} else {
fail();
}
},
fail: fail,
complete: complete,
});
},
globalData: {
userId: null,
token: null,
testUrl:"https://b**********op",
errorMsg: "网络开小差啦,请稍后重试!",
}
})
在页面中
引入app.js中的 globalData
这里就是为了方便切换域名 以及请求头,userId等…