使用浏览器自带的预览功能
function viewFile(url){
const suffix = url.split("/").pop().split(".").pop(); // 获取文件后缀
axios({
url,
method: "get",
responseType: "arraybuffer",
}).then((res) => {
// 将返回的数据转为blob对象,再生成一个url
const pdfFile = window.URL.createObjectURL(
new Blob([res.data], { type: "application/" + suffix })
);
// 新窗口打开新的url
window.open(pdfFile + "#toolbar=0");
});
}