download
formatFileNameAndDownloadFile
下载 网络请求 返回的 二进制流文件。
实现代码
ts
const handleExport = (urlApi: string, params: any) => {
return defHttp.post(
{
url: urlApi,
params,
responseType: 'blob'
},
{ isReturnNativeResponse: true, closeErrorModal: true }
);
};
handleExport(ApiStr, params).then(res => {
formatFileNameAndDownloadFile(res)
})downloadByData
下载文件流格式的文件
实现代码
ts
const fileData = 'xxxxx'
const fileName 'fileName'
downloadByData(fileData, fileName)API
formatFileNameAndDownloadFile
| 属性 | 描述 | 类型 | 默认值 |
|---|---|---|---|
| request | 网络请求返回参数 | any | - |
downloadByData
| 属性 | 描述 | 类型 | 默认值 |
|---|---|---|---|
| data | 二进制文件 | BlobPart | - |
| filename | 文件名称 | string | - |
| mime | 文件类型 | string | 'application/octet-stream' |
| bom | -- | BlobPart | - |