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

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);
          })
    }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容