小工具知识网

当前位置: 首页 > 行业知识 > vue3 blob下载流文件

行业知识

vue3 blob下载流文件

2026-11-15 15:57:48 来源:互联网转载

问题前���:需要把自己想要的内容转成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);}

上一篇:远程怎么装mysql服务器?

下一篇:服务器电源放在机箱哪里?