mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-05 03:05:07 +08:00
fix: request 属性代理问题
This commit is contained in:
parent
677a25d00d
commit
2cb7d5d4e0
@ -18,15 +18,23 @@ function getRequestInstance() {
|
||||
// 不能立马初始化,用户配置可能还没准备好
|
||||
let currentRequest;
|
||||
|
||||
export function rawRequest(url, data, options = {}) {
|
||||
function _rawRequest(url, data, options = {}) {
|
||||
if (!currentRequest) {
|
||||
currentRequest = getRequestInstance();
|
||||
// 将 request 实例上的属性挂在到 rawRequest 上。
|
||||
Object.assign(rawRequest, currentRequest);
|
||||
}
|
||||
return currentRequest(url, data, options);
|
||||
}
|
||||
|
||||
// 代理 request 上的属性
|
||||
export const rawRequest = new Proxy(_rawRequest, {
|
||||
get(_, key) {
|
||||
if (!currentRequest) {
|
||||
currentRequest = getRequestInstance();
|
||||
}
|
||||
return currentRequest[key];
|
||||
},
|
||||
});
|
||||
|
||||
export async function request(url, data, options = {}) {
|
||||
const response = await rawRequest(url, data, options);
|
||||
return response.data;
|
||||
|
Loading…
x
Reference in New Issue
Block a user