From 2cb7d5d4e0bf53ffd89fa8dd1b51266499642fac Mon Sep 17 00:00:00 2001 From: winixt Date: Fri, 14 Mar 2025 18:21:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20request=20=E5=B1=9E=E6=80=A7=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fes-plugin-request/src/template/request.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/fes-plugin-request/src/template/request.js b/packages/fes-plugin-request/src/template/request.js index cebde7ee..572dbe24 100644 --- a/packages/fes-plugin-request/src/template/request.js +++ b/packages/fes-plugin-request/src/template/request.js @@ -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;