From 693940c02106d28fda8613b95606ff6cb7f31720 Mon Sep 17 00:00:00 2001 From: * <*> Date: Wed, 6 Sep 2023 15:46:46 +0800 Subject: [PATCH] Match-id-55b5f86a1f1d697eedbd6697fbb22779a206ecf5 --- packages/inula-request/nodemon.json | 2 +- packages/inula-request/src/core/InulaRequest.ts | 10 ++++++++++ packages/inula-request/src/request/fetchRequest.ts | 5 ++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/inula-request/nodemon.json b/packages/inula-request/nodemon.json index 7520e744..94961eeb 100644 --- a/packages/inula-request/nodemon.json +++ b/packages/inula-request/nodemon.json @@ -7,5 +7,5 @@ "env": { "NODE_ENV": "development" }, - "ext": "js,json" + "ext": "js,mjs,json" } diff --git a/packages/inula-request/src/core/InulaRequest.ts b/packages/inula-request/src/core/InulaRequest.ts index 80be7d8f..7fb215f4 100644 --- a/packages/inula-request/src/core/InulaRequest.ts +++ b/packages/inula-request/src/core/InulaRequest.ts @@ -29,6 +29,16 @@ class InulaRequest implements IrInterface { response: new InterceptorManager(), }; this.processRequest = processRequest; + + // 支持动态传递请求方法保证 this 指向正确 + this.request = this.request.bind(this); + this.get = this.get.bind(this); + this.delete = this.delete.bind(this); + this.head = this.head.bind(this); + this.options = this.options.bind(this); + this.post = this.post.bind(this); + this.put = this.put.bind(this); + this.patch = this.patch.bind(this); } request(requestParam: string | Record, config?: IrRequestConfig): Promise> { diff --git a/packages/inula-request/src/request/fetchRequest.ts b/packages/inula-request/src/request/fetchRequest.ts index aaf1e2f3..c6eec758 100644 --- a/packages/inula-request/src/request/fetchRequest.ts +++ b/packages/inula-request/src/request/fetchRequest.ts @@ -21,10 +21,13 @@ export const fetchRequest = (config: IrRequestConfig): Promise => { withCredentials = false, onUploadProgress = null, onDownloadProgress = null, + signal, } = config; let controller = new AbortController(); - let signal = controller.signal; + if (!signal) { + signal = controller.signal; + } // 处理请求取消 if (cancelToken) {