app.js 中
request: function (url, data, method, callback, error) {
var header = {};
header = {
'content-type': 'application/x-www-form-urlencoded',
'token': wx.getStorageSync("token")
}
wx.request({
url: this.globalData.url + url,
data: data,
method: method,
header: header,
success: function (res) {
callback(res)
},
fail: function (msg) {
wx.showToast({
title: '请求失败或超时',
duration: 2000
})
},
})
},
在appjs中 写一个方法 url是请求地址
globalData: {
userInfo: null,
url: ''
},
接口调用
queryYear: function () {
var that = this;
app.request('',{}, "get", function (res) {
if (res.data.success) {
}
})
},
‘’ 请求地址
{} 参数