parent
5d45cd9670
commit
c0352a5d6a
|
@ -9,15 +9,15 @@ title: 开始
|
||||||
:::: code-group
|
:::: code-group
|
||||||
|
|
||||||
```bash [NPM]
|
```bash [NPM]
|
||||||
$ npm install -D axios-miniprogram
|
$ npm install axios-miniprogram
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash [YARN]
|
```bash [YARN]
|
||||||
$ yarn add -D axios-miniprogram
|
$ yarn add axios-miniprogram
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash [PNPM]
|
```bash [PNPM]
|
||||||
$ pnpm install -D axios-miniprogram
|
$ pnpm install axios-miniprogram
|
||||||
```
|
```
|
||||||
|
|
||||||
::::
|
::::
|
||||||
|
|
|
@ -432,7 +432,6 @@ export default class Axios {
|
||||||
declare connect: AxiosRequestMethodFn;
|
declare connect: AxiosRequestMethodFn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param config 默认配置
|
* @param config 默认配置
|
||||||
* @param parent 父级实例
|
* @param parent 父级实例
|
||||||
*/
|
*/
|
||||||
|
@ -468,12 +467,12 @@ export default class Axios {
|
||||||
| Partial<Interceptor<AxiosResponse>>
|
| Partial<Interceptor<AxiosResponse>>
|
||||||
)[] = [];
|
)[] = [];
|
||||||
|
|
||||||
this.eachRequestInterceptors((requestInterceptor) => {
|
this.eachInterceptors('request', (interceptor) => {
|
||||||
chain.unshift(requestInterceptor);
|
chain.unshift(interceptor);
|
||||||
});
|
});
|
||||||
chain.push(requestHandler);
|
chain.push(requestHandler);
|
||||||
this.eachResponseInterceptors((responseInterceptor) => {
|
this.eachInterceptors('response', (interceptor) => {
|
||||||
chain.push(responseInterceptor);
|
chain.push(interceptor);
|
||||||
});
|
});
|
||||||
chain.push(errorHandler);
|
chain.push(errorHandler);
|
||||||
|
|
||||||
|
@ -491,24 +490,16 @@ export default class Axios {
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
private eachRequestInterceptors(
|
private eachInterceptors<T extends 'request' | 'response'>(
|
||||||
executor: InterceptorExecutor<AxiosRequestConfig>,
|
type: T,
|
||||||
|
executor: InterceptorExecutor<
|
||||||
|
T extends 'request' ? AxiosRequestConfig : AxiosResponse
|
||||||
|
>,
|
||||||
) {
|
) {
|
||||||
this.interceptors.request.forEach(executor);
|
// @ts-ignore
|
||||||
|
this.interceptors[type].forEach(executor);
|
||||||
if (this.parent) {
|
if (this.parent) {
|
||||||
this.parent.eachRequestInterceptors(executor);
|
this.parent.eachInterceptors(type, executor);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
private eachResponseInterceptors(
|
|
||||||
executor: InterceptorExecutor<AxiosResponse>,
|
|
||||||
) {
|
|
||||||
this.interceptors.response.forEach(executor);
|
|
||||||
if (this.parent) {
|
|
||||||
this.parent.eachResponseInterceptors(executor);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue