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);
}
相关推荐
码事漫谈3 小时前
当AI开始“思考”:我们是否真的准备好了?
前端·后端
许杰小刀3 小时前
ctfshow-web文件包含(web78-web86)
android·前端·android studio
我是Superman丶4 小时前
Element UI 表格某行突出悬浮效果
前端·javascript·vue.js
恋猫de小郭4 小时前
你的代理归我了:AI 大模型恶意中间人攻击,钱包都被转走了
前端·人工智能·ai编程
xiaokuangren_5 小时前
前端css颜色
前端·css
Huanzhi_Lin5 小时前
关于V8/MajorGC/MinorGC——性能优化
javascript·性能优化·ts·js·v8·新生代·老生代
hoiii1875 小时前
C# 基于 LumiSoft 实现 SIP 客户端方案
前端·c#
anOnion5 小时前
构建无障碍组件之Meter Pattern
前端·html·交互设计
小码哥_常5 小时前
Spring Boot配置diff:解锁配置管理新姿势
前端
小码哥_常6 小时前
告别onActivityResult!Android数据回传的3大痛点与终极解决方案
前端