fetch(url'?id=b19a6c0c-56e2-4fd7-b948-74511c494594', {
method: 'GET',
}).then(ret => ret.blob())
.then(res => {
console.log(res);
var blob = new Blob([res], {
// type: 'image/jpeg;chartset=UTF-8' // e9f58b6f-adf0-4bdf-9d10-a074f2aa6186 图片
// type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document;chartset=UTF-8' // 0463375c-cdfd-46e5-992e-b0b34b047397 doc
type: 'application/pdf;chartset=UTF-8' // 9882523d-491b-40f8-af80-db54714a23e2
//type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;chartset=UTF-8' // 1f5e54c4-b97e-466b-ae1a-7ea0a19aa442 xlsx
})
var fileURL = URL.createObjectURL(blob)
this.pdfUrl = fileURL
将下载链接转为二进制流,就可以通过iframe预览
<iframe :src="pdfUrl" id="previewPdf" frameborder="0" style="width: 100%; height: 100%"></iframe>