40 lines
764 B
JavaScript
40 lines
764 B
JavaScript
function request (url, method, data, header = {}) {
|
|
wx.showLoading({
|
|
title: '加载中'
|
|
})
|
|
return new Promise((resolve, reject) => {
|
|
wx.request({
|
|
url: app.globalData.reqUrl+ url,
|
|
method: method,
|
|
data: data,
|
|
header: {
|
|
'content-type': 'application/json',
|
|
'Authorization': 'Bearer '+wx.getStorageSync('cookie').toString(),
|
|
...header
|
|
},
|
|
success: function (res) {
|
|
wx.hideLoading()
|
|
resolve(res.data)
|
|
},
|
|
fail: function (error) {
|
|
wx.hideLoading()
|
|
reject(error)
|
|
},
|
|
complete: function () {
|
|
wx.hideLoading()
|
|
}
|
|
})
|
|
})
|
|
}
|
|
function get (obj) {
|
|
return request(obj.url, 'GET', obj.data)
|
|
}
|
|
function post (obj) {
|
|
return request(obj.url, 'POST', obj.data)
|
|
}
|
|
|
|
export default {
|
|
request,
|
|
get,
|
|
post
|
|
} |