const baseURL = "https://wj.xhzrzdb.com/api/"
export const request = (options) => {
return new Promise((resolve, reject) => {
uni.showLoading({
title: '加载中',
mask: true
});
uni.request({
url: baseURL + options.url,
method: options.method || 'GET',
data: JSON.stringify(options.data) || {},
header: options.header || {
"content-type": 'application/x-www-form-urlencoded'
},
success: (res) => {
if (res.statusCode === 200||res.statusCode=='ok') {
resolve(res)
} else {
console.log(res)
}
},
fail: (err) => {
reject(err)
},
complete() {
uni.hideLoading();
}
})
})
}
uni-app request封装
最新推荐文章于 2024-04-25 14:03:47 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)