标签:字符流 window lse download parse move 解决 date() pre
因为edge浏览器虽然是用的谷歌的内核,但是本身还是ie浏览器使用ie浏览器导出的方法就可以解决
export function downloadFile(obj, name, suffix) { //obj是字符流 name是文件名,suffix是文件后缀传递的参数可根据个人情况 if (window.navigator.msSaveOrOpenBlob) { // 兼容IE const blob = new Blob([obj]); const fileName = parseTime(new Date()) + ‘-‘ + name + ‘.‘ + suffix navigator.msSaveBlob(blob, fileName); } else { const url = window.URL.createObjectURL(new Blob([obj])) const element = document.createElement(‘a‘) element.style.display = ‘none‘ element.href = url const fileName = parseTime(new Date()) + ‘-‘ + name + ‘.‘ + suffix element.setAttribute(‘download‘, fileName) document.body.appendChild(element) element.click() document.body.removeChild(element) } }
标签:字符流 window lse download parse move 解决 date() pre
原文地址:https://www.cnblogs.com/lovetl/p/12978727.html