vue 下载 流文件 导出表格
发布日期:2021-05-10 15:39:32 浏览次数:23 分类:精选文章

本文共 2199 字,大约阅读时间需要 7 分钟。

Vue���������������������������������������������

���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������JS-File-Download������

������������

������������������������������������������

npm install js-file-download --save

������������

���������������������������������������������

var fileDownload = require("js-file-download");

������������

������������������������������������������

exportExport(������).then(res => {
// ������������������������headers���������������content-disposition������
let fileName = res.headers['content-disposition'].match(/fushun(\S*)xls/)[0];
fileDownload(res.data, fileName);
}).catch(error => {
console.log(error);
});

������������

  • fileDownload ������������������������������������������������������������������������������
  • fileName ���������������������������������������������������������������������������-disposition������������������������

������������������ Blob ������

������������

exportExport(������).then(res => {
// ��������������������� Blob
let blob = new Blob([res], {
type: "application/vnd.ms-excel"
});
// ������������ URL ���������
let objectUrl = URL.createObjectURL(blob);
window.location.href = objectUrl;
}).catch(error => {
console.log(error);
});

������������

  • ������ Blob ������������������������������������������ MIME ��������� Excel ��������������� application/vnd.ms-excel���
  • ������������ URL ������������������������������������������������������

������������

  • headers������������������������������ Content-Disposition ���������������������������������������������������������������������������������
  • ������������������������������ Blob ��� URL.createObjectURL ���������������������������������������������������������������������
  • ���������������������������������������������������������������������������������
  • ��������������������������������������������������� Vue ������������������������������������������������������������������������������������������������������������������

    上一篇:elementui el-input记住密码之后选择的账号和密码,改变了背景颜色
    下一篇:vue 修改当前路由的名称

    发表评论

    最新留言

    哈哈,博客排版真的漂亮呢~
    [***.90.31.176]2025年04月29日 14时12分26秒