mirror of
https://gitee.com/WeBank/fes.js.git
synced 2024-12-03 12:17:38 +08:00
feat: 针对请求文件的情况进行优化 (#91)
This commit is contained in:
parent
d98f326e5f
commit
e00acc4a7e
@ -1,6 +1,15 @@
|
||||
import { isFunction, isObject, isString } from './helpers';
|
||||
|
||||
export default async ({ response, responseDataAdaptor }, next) => {
|
||||
// 如果 data 是 blob 并且 content-type 是 application/json,自动进行数据处理
|
||||
if (response.data instanceof Blob && response.headers['content-type'].startsWith('application/json') && response.data.type === 'application/json') {
|
||||
const rawData = response.data;
|
||||
try {
|
||||
response.data = JSON.parse(await response.data.text());
|
||||
} catch {
|
||||
response.data = rawData;
|
||||
}
|
||||
}
|
||||
if (isFunction(responseDataAdaptor) && response && (isObject(response.data) || isString(response.data))) {
|
||||
response.data = responseDataAdaptor(response.data);
|
||||
}
|
||||
|
@ -65,16 +65,19 @@ export default {
|
||||
};
|
||||
|
||||
const post = (id) => {
|
||||
request('/get/api', { id }, {
|
||||
request('/api', { id }, {
|
||||
responseType: 'blob'
|
||||
}).then((data) => {
|
||||
console.log(data);
|
||||
});
|
||||
};
|
||||
|
||||
get(1);
|
||||
get(2);
|
||||
get(3);
|
||||
// get(2);
|
||||
// get(3);
|
||||
|
||||
post(1);
|
||||
post(2);
|
||||
// post(1);
|
||||
// post(2);
|
||||
post(3);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user