From 8ebefe27259537a9a9e3dfdc24b129c8f7f9031a Mon Sep 17 00:00:00 2001 From: JOU Amjs Date: Wed, 18 Dec 2024 21:04:08 +0800 Subject: [PATCH] docs: add `onCreate` callback to adapter xhr --- docs/resource/01-request-adapter/03-xhr.md | 15 +++++++++++++++ .../current/resource/01-request-adapter/03-xhr.md | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/docs/resource/01-request-adapter/03-xhr.md b/docs/resource/01-request-adapter/03-xhr.md index 77352f412..95a587b9e 100644 --- a/docs/resource/01-request-adapter/03-xhr.md +++ b/docs/resource/01-request-adapter/03-xhr.md @@ -48,6 +48,21 @@ const alovaInst = createAlova({ }); ``` +When you need to access the internal XMLHttpRequest instance, you can get the instance through the `create` callback function. + +```javascript +const alovaInst = createAlova({ + // ... + requestAdapter: xhrRequestAdapter({ + onCreate(xhr) { + // Access xhr instance + // ... + } + }) + // ... +}); +``` + ### Request The XMLHttpRequest adapter provides basic configuration parameters, including `responseType`, `withCredentials`, `mimeType`, `auth`, as follows: diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/resource/01-request-adapter/03-xhr.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/resource/01-request-adapter/03-xhr.md index dfca648a6..370799fff 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/resource/01-request-adapter/03-xhr.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/resource/01-request-adapter/03-xhr.md @@ -48,6 +48,21 @@ const alovaInst = createAlova({ }); ``` +当需要访问内部的XMLHttpRequest 实例时,可以通过`create`回调函数获取到实例。 + +```javascript +const alovaInst = createAlova({ + // ... + requestAdapter: xhrRequestAdapter({ + onCreate(xhr) { + // 访问xhr实例 + // ... + } + }) + // ... +}); +``` + ### 请求 XMLHttpRequest 适配器提供了基本的配置参数,包含`responseType`、`withCredentials`、`mimeType`、`auth`,具体如下: