极简模式:pdf 预览
handelDownload(row) {
this.$axios({
method: "get",
url: baseUrl + getUrl,
responseType: "arraybuffer",
header: { "Content-Type": "multipart/form-data" },
params: {
billId: row.id,
},
}).then((resp) => {
const binaryData = [];
binaryData.push(resp.data);
//获取blob链接
this.pdfUrl = window.URL.createObjectURL(new Blob(binaryData, { type: 'application/pdf' }));
window.open(this.pdfUrl);
});
},
下载模式:pdf 下载
handelDownload(row) {
request({
url: baseUrl + getUrl,
method: "put",
responseType: "blob",
header: { "Content-Type": "multipart/form-data" },
data: {
idList: this.ids,
},
})
.then((res) => {
const url = window.URL.createObjectURL(new Blob([res.data]));
const link = window.document.createElement("a");
link.style.display = "none";
link.href = url;
link.setAttribute("download", "pdf" + ".zip");
document.body.appendChild(link);
link.click();
})
.catch((res) => {
});
},
文件流模式:
this.$axios({
method: "get",
url: baseUrl + getUrl,
responseType: "arraybuffer",
header: { "Content-Type": "multipart/form-data" },
params: {
billId: row.id,
},
}).then((resp) => {
const binaryData = [];
binaryData.push(resp.data);
//获取blob链接
this.pdfUrl = window.URL.createObjectURL(
new Blob(binaryData, { type: "application/pdf" })
);
this.keyValue = row.id;
this.flag = true;
});
<iframe :src="pdfUrl" page="0" frameborder="0" style="width: 100%; height: 100%"></iframe>
vue-pdf 预览和下载
于 2022-03-25 10:50:53 首次发布
本文介绍三种不同的PDF处理方式:极简模式预览PDF,下载模式直接下载PDF为ZIP,及文件流模式显示PDF。通过不同场景下的实现代码示例,帮助读者理解如何在Web应用中集成这些功能。
4247

被折叠的 条评论
为什么被折叠?



