WEB端接收后端文件流函数

149 阅读1分钟
//以POST方式请求下载文件流
postDownload({ url, data, fileType = 'xlsx' }) {
    this.api({
        url: url,
        data: data,
        method: "POST",
        responseType: "blob"
    }).then(res => {
        const blob = new Blob([res]);
        const blobUrl = window.URL.createObjectURL(blob);
        const a = document.createElement('a');
        const date = new Date();
        a.download = date.getTime() + '.' + fileType;
        a.href = blobUrl;
        a.click();
    })
}