这里我用的是axios 所以就只说一下axios吧
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);//这里是直接打开新窗口
});
http content-type 链接HTTP content-type链接