From 0e7e7d2132fc933be229e016fe2dd577f356b431 Mon Sep 17 00:00:00 2001 From: winixt Date: Thu, 28 Mar 2024 18:26:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=20reqeust=20=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=96=87=E4=BB=B6=E6=B5=81=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/fes-plugin-request/package.json | 74 +++++++++---------- packages/fes-plugin-request/src/index.js | 6 +- .../src/template/request.js | 16 ++-- 3 files changed, 49 insertions(+), 47 deletions(-) diff --git a/packages/fes-plugin-request/package.json b/packages/fes-plugin-request/package.json index fcef4a5d9..3a0a33720 100644 --- a/packages/fes-plugin-request/package.json +++ b/packages/fes-plugin-request/package.json @@ -1,39 +1,39 @@ { - "name": "@fesjs/plugin-request", - "version": "4.0.0-rc.1", - "description": "@fesjs/plugin-request", - "main": "lib/index.js", - "files": [ - "lib", - "types.d.ts" - ], - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/WeBankFinTech/fes.js.git", - "directory": "packages/fes-plugin-request" - }, - "keywords": [ - "fes" - ], - "author": "qlin", - "license": "MIT", - "bugs": { - "url": "https://github.com/WeBankFinTech/fes.js/issues" - }, - "homepage": "https://github.com/WeBankFinTech/fes.js#readme", - "publishConfig": { - "access": "public" - }, - "peerDependencies": { - "@fesjs/fes": "^3.1.4", - "vue": "^3.2.37" - }, - "dependencies": { - "@fesjs/utils": "^3.0.1", - "@qlin/request": "^0.1.2" - }, - "typings": "./types.d.ts" + "name": "@fesjs/plugin-request", + "version": "4.0.0-rc.1", + "description": "@fesjs/plugin-request", + "author": "qlin", + "license": "MIT", + "homepage": "https://github.com/WeBankFinTech/fes.js#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/WeBankFinTech/fes.js.git", + "directory": "packages/fes-plugin-request" + }, + "bugs": { + "url": "https://github.com/WeBankFinTech/fes.js/issues" + }, + "keywords": [ + "fes" + ], + "main": "lib/index.js", + "files": [ + "lib", + "types.d.ts" + ], + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "publishConfig": { + "access": "public" + }, + "peerDependencies": { + "@fesjs/fes": "^3.1.4", + "vue": "^3.2.37" + }, + "dependencies": { + "@fesjs/utils": "^3.0.1", + "@qlin/request": "^0.2.0" + }, + "typings": "./types.d.ts" } diff --git a/packages/fes-plugin-request/src/index.js b/packages/fes-plugin-request/src/index.js index 019b2d401..e2c78059c 100644 --- a/packages/fes-plugin-request/src/index.js +++ b/packages/fes-plugin-request/src/index.js @@ -1,4 +1,4 @@ -import { join } from 'path'; +import { join } from 'node:path'; import { name } from '../package.json'; export default (api) => { @@ -9,7 +9,9 @@ export default (api) => { let generatedOnce = false; api.onGenerateFiles(() => { - if (generatedOnce) return; + if (generatedOnce) { + return; + } generatedOnce = true; api.copyTmpFiles({ namespace, diff --git a/packages/fes-plugin-request/src/template/request.js b/packages/fes-plugin-request/src/template/request.js index 8f19d59cc..47a044d85 100644 --- a/packages/fes-plugin-request/src/template/request.js +++ b/packages/fes-plugin-request/src/template/request.js @@ -9,7 +9,6 @@ function getRequestInstance() { type: ApplyPluginsType.modify, initialValue: { timeout: 10000, - responseType: 'json', }, }); @@ -18,7 +17,7 @@ function getRequestInstance() { let currentRequest; -export const rawRequest = (url, data, options = {}) => { +export function rawRequest(url, data, options = {}) { if (typeof options === 'string') { options = { method: options, @@ -28,12 +27,12 @@ export const rawRequest = (url, data, options = {}) => { currentRequest = getRequestInstance(); } return currentRequest(url, data, options); -}; +} -export const request = async (url, data, options = {}) => { +export async function request(url, data, options = {}) { const response = await rawRequest(url, data, options); return response.data; -}; +} request.version = '4.0.0'; @@ -41,14 +40,15 @@ function isPromiseLike(obj) { return !!obj && typeof obj === 'object' && typeof obj.then === 'function'; } -export const useRequest = (url, data, options = {}) => { +export function useRequest(url, data, options = {}) { const loadingRef = ref(true); const errorRef = ref(null); const dataRef = shallowRef(null); let promise; if (isPromiseLike(url)) { promise = url; - } else { + } + else { promise = request(url, data, options); } promise @@ -66,4 +66,4 @@ export const useRequest = (url, data, options = {}) => { error: errorRef, data: dataRef, }; -}; +}