Axios IE 11问题, 无法下载响应类型blob

问题描述 投票:0回答:1
axios.get("http://localhost:63542/api/v1/WorkInst",
            {
                responseType: 'arraybuffer',
                headers: {
                    'Content-Type': 'application/json',
                    'Accept': 'application/pdf'
                }
            })
            .then((response) => {
                console.log(response);
                var blob = new Blob([response.data], {type: 'application/pdf'});
                var downloadUrl = URL.createObjectURL(blob);
                var a = document.createElement("a");
                a.href= downloadUrl;
                a.download = ("test.pdf");
                a.click();


            })
            .catch((error) => console.log(error));

但不是下载,而是“您要允许该网站在您的计算机上打开应用吗?”但是它正在使用谷歌浏览器和mozilla firefox。急需对此的帮助

reactjs internet-explorer axios
1个回答
0
投票

据我所知,Download attribute不支持IE浏览器。因此,在IE和Edge浏览器中,获取文件数据后,可以使用msSaveOrOpenBlob方法在IE和Edge浏览器中下载文件,而在Chrome或Firefox浏览器中,可以创建超链接以使用以下链接下载文件网址。更多详细信息,请检查此样本:

© www.soinside.com 2019 - 2024. All rights reserved.