摘自: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);//這里是直接打開新窗口
});