we.request请求封装
第一步在utils下面创建一个http.js,
let sUrl = "https://www.baidu.com";
function getData (url, data, nb) {
wxrequest({
url: sUrl + url,
data: data,
method: 'post',
header: {
// "ContentType": "json", //get请求时候"ContentType": "applicationwwwformurlencoded", //POST请求的时候这样写
'token': wx.getStorageSync('token')
},
success: functionres) {
returntypeof nb == "function" && nb(res.data)
},
fail: functionres) {
returntypeof nb == "function" && nb(res.data)
}
})
}
module.exports = {
req: getData
}
第二步在app.js引入
let http = require ('utils/http.js')
//封装请求res: {
req: http.req //这里配置我们需要的方法
},
然后在你需要的页面直接应用
letdata = {
}//data是你要传的参数
app.res.req('app-web/userproject/list', data, (res) => {
})

