const BASE_URL = 'http://xxxx'
module.exports = (options) => {
let url = BASE_URL + options.url;
let method = options.method || 'GET';
let header = options.header || {};
let data = options.data || {};
if (method) {
method = method.toUpperCase();
if (method == 'POST') {
if(!header) {
header = {
"content-type": "application/json"
}
}
}
}
if (!options.hideLoading) {
uni.showLoading({
title: '拼命加载中...'
})
}
return new Promise((resolve,reject) => {
uni.request({
url: url,
method: method,
data: data,
dataType: "json",
sslVerify: false,
header: header,
success: res => {
if (res.data.code && res.data.code != 200) {
uni.showToast({
title: res.data.msg,
icon: 'none'
});
return;
}
resolve(res.data)
},
fail: err => {
uni.showToast({
title: res.data.msg,
icon: 'none'
});
reject(res.data)
},
complete: e => {
uni.hideLoading()
return;
}
})
})
}
封装一个uni.request
最新推荐文章于 2024-07-16 17:38:41 发布