vue3 blob下载流文件

问题前提:需要把自己想要的内容转成txt文件里的内容并可以下载

解决过程:

首先,根据想要的文件后缀,确定blob的类型,

.doc对应application/msword,

.docx对应application/vnd.openxmlformats-officedocument.wordprocessingml.document,

.xls对应application/vnd.ms-excel,

.xlsx对应application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,

.txt对应text/plain,
其次,形成流文件时,一定要记得JSON.stringify

解决结果:

const operRecordLog = ()=>{
    let operLog = JSON.stringify(list)//list是要放入txt文件中的内容
    const blob = new Blob([operLog], { type: 'text/plain' });
    const url = window.URL.createObjectURL(blob);
    const link = document.createElement('a');
    link.href = url;
    link.download = '日志.txt'; // 指定保存的文件名
    link.click()
    window.URL.revokeObjectURL(url);
}

相关推荐

  1. vue3 blob下载文件

    2024-03-10 22:48:06       20 阅读
  2. vue下载文件文档打开只有[object Blob](排错)

    2024-03-10 22:48:06       49 阅读
  3. blob文件前端显示pdf

    2024-03-10 22:48:06       23 阅读
  4. 前端下载文件

    2024-03-10 22:48:06       12 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-10 22:48:06       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-10 22:48:06       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-10 22:48:06       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-10 22:48:06       20 阅读

热门阅读

  1. vue 菜鸟教学如何jason字符串转对象

    2024-03-10 22:48:06       19 阅读
  2. 音频视频如何转字幕,音频视频转字幕教程

    2024-03-10 22:48:06       27 阅读
  3. 【深度学习】Pytorch基础

    2024-03-10 22:48:06       20 阅读
  4. 基于python的可视化开发

    2024-03-10 22:48:06       19 阅读
  5. excel 如何自动调整行间距 vba

    2024-03-10 22:48:06       20 阅读
  6. 【48天笔试强训】day8

    2024-03-10 22:48:06       22 阅读
  7. https 加密解密过程是什么?

    2024-03-10 22:48:06       22 阅读