Crmeb/app/utils/request.js

37 lines
801 B
JavaScript
Raw Normal View History

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