//app.js App({ onLaunch: function () { // 展示本地存储能力 var logs = wx.getStorageSync('logs') || [] logs.unshift(Date.now()) wx.setStorageSync('logs', logs) }, onshow:function(){ }, //网络请求 netPost(options = {}) { wx.showLoading({ mask: true, title: '', }) wx.request({ url: this.globalData.postUrl + options._url, data: options._data || {}, method: "POST", dataType: "json", header: this.globalData.header, success: (res) => { if (res.data.errcode > 0) { if (typeof options._success == "function") { options._success(res.data); } } else { this.xcxErrorToast({ title: res.data.errmsg || '服务器返回错误!' }); return; } }, fail: (res) => { if (typeof options._fail == "function") { options._fail(res); } if (typeof options._fail == "string") { //请求失败的弹框提示 wx.showToast({ title: options._fail, icon: 'loading', duration: 2000 }); } }, complete: (res) => { if (typeof options._complete == "function") { options._complete(res); } wx.hideLoading() } }); }, //全局属性 globalData: { userInfo: {}, postUrl: (wx.getExtConfigSync().request_url || '(后台接口地址)'), header: { 'content-type': 'application/x-www-form-urlencoded', 'Cookie': '' }, } })