mirror of
https://gitee.com/WeBank/fes.js.git
synced 2024-12-02 03:37:57 +08:00
fix: 解决 reqeust 生成文件流的问题 (#239)
This commit is contained in:
parent
0f672afd3b
commit
c369572c41
@ -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"
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user