在钉钉更新接口前,可以先在代码里实现一个 request
函数:
const AV = require("leancloud-storage");
const adapters = require("@leancloud/platform-adapters-alipay");
function request (url, options = {}) {
const { method, data, headers, signal } = options;
const newAbortError = (msg) => {
const err = new Error(msg);
err.name = "AbortError";
return err;
}
if (signal && signal.aborted) {
return Promise.reject(newAbortError('Request aborted'));
}
return new Promise((resolve, reject) => {
const task = my.httpRequest({
method,
url,
headers,
data: JSON.stringify(data),
complete: (res) => {
if (res.status) {
resolve({
ok: !(res.status >= 400),
status: res.status,
headers: res.headers,
data: res.data,
});
} else {
reject(new Error(`${res.error}: ${res.errorMessage}`));
}
},
});
if (signal) {
signal.addEventListener("abort", () => {
reject(newAbortError("Request aborted"));
task.abort();
});
}
});
};
AV.setAdapters({ ...adapters, request });
这样就可以兼容钉钉小程序了。您可以试一下。