From c0352a5d6a762e5b68c80a2c726e7b51a06eb887 Mon Sep 17 00:00:00 2001 From: zjxxxxxxxxx <43126836+zjxxxxxxxxx@users.noreply.github.com> Date: Thu, 25 Jan 2024 19:12:17 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E4=BF=AE=E5=A4=8D=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E9=94=99=E8=AF=AF=20(#58)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #57 --- docs/pages/guide/quick-start.md | 6 +++--- src/core/Axios.ts | 33 ++++++++++++--------------------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/docs/pages/guide/quick-start.md b/docs/pages/guide/quick-start.md index c106d52..1d4a642 100644 --- a/docs/pages/guide/quick-start.md +++ b/docs/pages/guide/quick-start.md @@ -9,15 +9,15 @@ title: 开始 :::: code-group ```bash [NPM] -$ npm install -D axios-miniprogram +$ npm install axios-miniprogram ``` ```bash [YARN] -$ yarn add -D axios-miniprogram +$ yarn add axios-miniprogram ``` ```bash [PNPM] -$ pnpm install -D axios-miniprogram +$ pnpm install axios-miniprogram ``` :::: diff --git a/src/core/Axios.ts b/src/core/Axios.ts index e9ed84b..b6939c2 100644 --- a/src/core/Axios.ts +++ b/src/core/Axios.ts @@ -432,7 +432,6 @@ export default class Axios { declare connect: AxiosRequestMethodFn; /** - * * @param config 默认配置 * @param parent 父级实例 */ @@ -468,12 +467,12 @@ export default class Axios { | Partial> )[] = []; - this.eachRequestInterceptors((requestInterceptor) => { - chain.unshift(requestInterceptor); + this.eachInterceptors('request', (interceptor) => { + chain.unshift(interceptor); }); chain.push(requestHandler); - this.eachResponseInterceptors((responseInterceptor) => { - chain.push(responseInterceptor); + this.eachInterceptors('response', (interceptor) => { + chain.push(interceptor); }); chain.push(errorHandler); @@ -491,24 +490,16 @@ export default class Axios { /** * @internal */ - private eachRequestInterceptors( - executor: InterceptorExecutor, + private eachInterceptors( + type: T, + executor: InterceptorExecutor< + T extends 'request' ? AxiosRequestConfig : AxiosResponse + >, ) { - this.interceptors.request.forEach(executor); + // @ts-ignore + this.interceptors[type].forEach(executor); if (this.parent) { - this.parent.eachRequestInterceptors(executor); - } - } - - /** - * @internal - */ - private eachResponseInterceptors( - executor: InterceptorExecutor, - ) { - this.interceptors.response.forEach(executor); - if (this.parent) { - this.parent.eachResponseInterceptors(executor); + this.parent.eachInterceptors(type, executor); } }