微前端产品开发中使用到了 umi-request 这个,类似于 axios(但貌似又强于 axios),因为碰到文件下载的功能,也即是:获取数据流,记录一下。 其实最重要的两点无非是: responseType 要设置成 blob https://github.com/blueju/umi-request-practice/blob/4f11c63e7b47f730ed1bcdde867c6f4575241485/example/get-data-s...
importrequestfrom"umi-request";request.get("/api/v1/xxx?id=1").then(function(response){console.log(response);}).catch(function(error){console.log(error);});// 也可将 URL 的参数放到 options.params 里request.get("/api/v1/xxx",{params:{id:1}}).then(function(response){console.log(res...
revokeObjectURL(objectURL); btn = null; }); } function sendFile() { request('http://localhost:2000/sendFile', { method: 'GET', responseType: 'blob', }).then(result => { console.log(result) // 需要指定文件类型,谷歌浏览器不能打开xlsx、doc等等 var blob = new Blob([result], { ...
umi-request/src/index.d.ts Version: 2.96 kBTypeScriptView Raw 1 export type ResponseType = 'json' | 'text' | 'blob' | 'arrayBuffer' | 'formData'; 2 3 /** 4 * 增加的参数 5 * @param {string} requestType post类型, 用来简化写content-Type, 默认json ...
{method:'get',getResponse:true,responseType:'blob',});if(response.ok){varblob=data;varfilename=url.split('/').pop();// 获取链接最后一节当文件名 = "subDeviceRelations.txt"vara=document.createElement('a');//创键临时url对象varurl=URL.createObjectURL(blob);a.href=url;a.download=filename...
request(url, { method: 'POST', body: JSON.stringify(params), responseType: 'blob', getResponse: true // 重点 }); //导出 onExport = () => { const { dispatch } = this.props; let filename = ``; dispatch({ type: 'xxx/onExport', }) .then((res) => { const disposition = ...
requestType post request data type string json , form json parseResponse response processing simplification boolean -- true charset character set string utf8 , gbk utf8 responseType How to parse the returned data string json , text , blob , formData ... json , text throwErrIfParseFail throw ...
export default () => { function download() { request('http://localhost:2000/download', { method: 'GET', responseType: 'blob', }).then(res => { console.log(res) const blob = new Blob([res]); const objectURL = URL.createObjectURL(blob); let btn = document.createElement('a'); bt...
requestTypepost 请求时数据类型stringjson , formjson parseResponse是否对 response 做处理简化boolean--true charset字符集stringutf8 , gbkutf8 responseType如何解析返回的数据stringjson , text , blob , formData ...json , text throwErrIfParseFail当 responseType 为 'json', 对请求结果做 JSON.parse 出错时...
requestTypepost request data typestringjson , formjson parseResponseresponse processing simplificationboolean--true charsetcharacter setstringutf8 , gbkutf8 responseTypeHow to parse the returned datastringjson , text , blob , formData ...json , text ...