/* 授权的get请求 */
export function ahthGet(url, data, config) {
console.log(data);
let userInfo = wx.getStorageSync('login')
return new Promise((resolve, reject) => {
wx.showLoading({
title: '加载中',
})
wxp.request({
url: url,
method: 'GET',
params: data,
header: {
'x-auth-user': userInfo.username,
'x-auth-token': userInfo.token,
},
}).then(res => {
wx.hideLoading()
resolve(res.data)
}).catch(e => {
wx.hideLoading()
reject(e.data)
})
})
}
/* 授权的post请求 */
export function ahthPost(url, data, config) {
let userInfo = wx.getStorageSync('login')
return new Promise((resolve, reject) => {
wx.showLoading({
title: '加载中',
})
wxp.request({
url: url,
method: 'POST',
data: data,
header: {
'x-auth-user': userInfo.username,
'x-auth-token': userInfo.token,
},
}).then(res => {
wx.hideLoading()
resolve(res.data)
}).catch(e => {
wx.hideLoading()
reject(e.data)
})
})
}
微信小程序封装异步请求
最新推荐文章于 2024-10-17 15:09:22 发布