
 后端返回的文件流
 前端需要处理成下载文件
 刚开始一直报错
 
 处理的方法
// http.js
import instance from './axios';
export const get = (url, params = {}, config = {}) => instance.get(url, { params, ...config });
// api.js
/**
 * 获取下载错误信息
 * @param {string} batchId - 批次ID
 * @returns {Promise} - 返回一个Promise对象,用于异步获取服务器响应
 */
export const downloadErrorMessage = (batchId, config = {}) => {
  return get(`/admin/finance/enterprise-authorization/downloadErrorMessage/${batchId}`, {}, config);
};
重点就是config配置 responseType: ‘blob’
页面代码
  downloadErrorMessage(res.data.batchId, { responseType: 'blob' }).then((response) => {
                  // 处理二进制数据并创建 Blob 对象
                  const blobObj = new Blob([response.data], {
                    'content-type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8',
                  });
                  saveAs(blobObj, 'error.xls'); // 这个是用的插件,不用插件可以自己创建a标签
                  handleClose();
                  emits('init');
                });
插件使用
 使用 npm 安装 FileSaver.js:
npm install file-saver --save
页面引入
import { saveAs } from 'file-saver';



















