37 lines
804 B
JavaScript
37 lines
804 B
JavaScript
/**
|
||
* @param {string} url 请求地址
|
||
* @param {string} method 请求方法(GET/POST)
|
||
* @param {string|object|arraybuffer} data 请求数据
|
||
*/
|
||
function request(url, method, data) {
|
||
wx.showLoading({
|
||
title: '加载数据...',
|
||
mask: true
|
||
});
|
||
|
||
const promise = new Promise((resolve, reject) => { // 修正:Pomise → Promise
|
||
wx.request({
|
||
url: url,
|
||
method: method.toUpperCase(), // 确保 method 是大写(GET/POST)
|
||
data: data,
|
||
header: {
|
||
'Content-Type': 'application/x-www-form-urlencoded' // 默认表单格式
|
||
},
|
||
success(res) {
|
||
resolve(res);
|
||
},
|
||
fail(err) {
|
||
reject(err);
|
||
},
|
||
complete() {
|
||
wx.hideLoading();
|
||
}
|
||
});
|
||
});
|
||
|
||
return promise;
|
||
}
|
||
|
||
module.exports = {
|
||
request
|
||
}; |