let baseUrl = 'http://47.103.51.84:9091/'
let request = function(url, data = {}, method = 'GET') {
return new Promise((resole, reject) => {
uni.showLoading({
title:'加载中...'
})
uni.request({
url: baseUrl + url,
method: method,
data: data,
header: {
'Content-Type': 'application/json;charset=utf-8',
'token':uni.getStorageSync('token')
},
success(res) {
uni.hideLoading()
if (res.statusCode == 200 && res.data.code == 0) {
resole(res.data)
return
}
uni.showToast({
title: '请求失败',
icon:'none'
})
resole(res.data)
},
fail(err) {
uni.hideLoading()
uni.showToast({
title: '请求失败',
icon:'none'
})
reject(err)
}
})
})
}
let post = function(url,data){
return request(url,data,"POST")
}
let get = function(url,data){
return request(url,data)
}
export {post,get}
uni.request封装
最新推荐文章于 2024-05-30 21:45:00 发布