摘自:https://blog.csdn.net/sinat_39648402/article/details/105664037
Axios({
methods: ‘GET‘,
url: ‘url’,
responseType: ‘blob‘//这里意思是接收返回文件格式
}).then(res => {
let blob = new Blob([res.data], {
type: ‘text/xml‘/我这里接收的是svg 其他类型参考HTTP content-type
});
let fileURL = URL.createObjectURL(blob);
//如果你是在一个标签元素中显示这个文件,还是以我用的svg为例
//可以写成<embed src=fileURL type="text/xml" />对pdf同样适用,注意改一下type
window.open(fileURL);//这里是直接打开新窗口
});
原文:https://www.cnblogs.com/modestlin/p/13946766.html