下载文件兼容ie

下载文件兼容ie

        const data = await requestInterface(); //请求接口
        const binaryData = []
        binaryData.push(data.data)  //放入数据
        let blob = new Blob([data.data], {type: data.headers['content-type']})
        let fileName = data.headers['content-disposition'].split(';')[1].split('=')[1]
        fileName = decodeURI(fileName)
        let urlPdf = window.URL.createObjectURL(blob)
        if (window.navigator && window.navigator.msSaveOrOpenBlob) {  //兼容ie
            window.navigator.msSaveOrOpenBlob(new Blob(binaryData, { type: data.type }), fileName)
        } else {
            const link = document.createElement("a")
            link.style.display = "none"
            link.href = urlPdf
            link.setAttribute("download", fileName)
            document.body.appendChild(link)
            link.click()
            URL.revokeObjectURL(link.href) // 释放URL 对象
            document.body.removeChild(link)
        }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容