這裏我用的是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鏈接