一、新建一个文件夹,下新建一个request.js文件
const API_BASE_URL = 'baseurl';
const request = (url, method, data = {}) => {
return new Promise((resolve, reject) => {
wx.request({
url: API_BASE_URL + url,
method: method,
data: data,
header: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': wx.getStorageSync('token')
},
success(res) {
resolve(res.data)
},
fail(error) {
reject(error)
}
})
})
}
let getInfo = (code) => {
var mydata={};
return request('urls/info', 'post', mydata)
}
module.exports={
getInfo: getInfo,
request:request
}
2、具体引用
onShow(){
req.getInfo().then((res) => {
console.log('arrarr',res);
})
},