Crmeb/app/utils/request.js
2025-04-28 17:55:43 +08:00

37 lines
804 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @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
};