const previewPdf = () => {
axios({
method: 'get', // 請(qǐng)求方式
responseType: 'blob',
url: '/afa/pdfxxx', // 請(qǐng)求路徑
}).then((res = {}) => {
if (`${res.status}` === '200') {
if (window.navigator.msSaveBlob) { // IE
//IE無(wú)法打開(kāi)Blob URL鏈接,所以不能預(yù)覽只能通過(guò)window.navigator.msSaveBlob下載
//注:msSaveBlob的第二個(gè)參數(shù)要有.pdf后綴,不然IE下載后是沒(méi)有后綴的文件
const blob = new window.Blob([res.data], { type: 'application/pdf;charset-UTF-8' });
window.navigator.msSaveBlob(blob, `${filename}.pdf`);
} else {
const blob = new window.Blob([res.data], {
type: 'application/pdf;charset-UTF-8',
});
const href = URL.createObjectURL(blob);
window.open(href);
}
}
});
};
如果沒(méi)有自動(dòng)打開(kāi)預(yù)覽,可能是這個(gè)地方攔截了,點(diǎn)擊它將攔截關(guān)閉

image.png