diff --git a/packages/fes-plugin-request/package.json b/packages/fes-plugin-request/package.json index fcef4a5d..3a0a3372 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 019b2d40..e2c78059 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 8f19d59c..47a044d8 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, }; -}; +}