美文网首页
2022-12-14 解决下载txt浏览器直接打开的问题

2022-12-14 解决下载txt浏览器直接打开的问题

作者: 遗忘的灬誓言 | 来源:发表于2022-12-13 09:22 被阅读0次
const fileDownload = (item: Object) => {
        console.log(item.recordName);
        let url = SYSTEM_CONFIG.services.BASE_API + item.url;
                window.fetch(url).then(res => {
            return res.blob()
        }).then(blob => {
                        let a = document.createElement('a');
            a.href = window.URL.createObjectURL(blob);
            a.setAttribute('download', item.recordName);
            a.target = '_blank';
            a.style.display = 'none';
                        document.body.appendChild(a);
            a.click();
            a.remove();
            window.URL.revokeObjectURL(url);
          })
    }

相关文章

网友评论

      本文标题:2022-12-14 解决下载txt浏览器直接打开的问题

      本文链接:https://www.haomeiwen.com/subject/awkhqdtx.html