const baseUrl = ''
export function request(url, method, data, header) {
return new Promise(function (resolve, reject) {
wx.request({
url: baseUrl + url,
method: method,
data: method === 'POST' ? JSON.stringify(data) : data,
header: {
'content-type': 'application/json',
'X-Auth-Token': getApp().globalData.token,
...header
},
success(res) {
if (res.statusCode == 200) {
resolve(res.data)
}else {
reject()
wx.showToast({
title: '服务器异常',
icon: 'none',
duration: 2000
})
}
},
fail(err) {
reject()
wx.showToast({
title: '服务器异常',
icon: 'none',
duration: 2000
})
}
})
})
}
外部模块引用后使用async+await即可