1、注意后端返回的base64是否正确,有没有换行,特殊字符等
showpdf(data) {
this.$store.commit("SET_PDFDATA", data);
this.$router.push({ path: "/pdf" });
}
pdf.vue
<template>
<div style="width: 100%; height: 100vh; margin: 0 auto">
<iframe
:src="pdfsrc"
frameborder="0"
filepath="filename.pdf"
type="application/pdf"
style="width: 100%; height: 100%"
></iframe>
</div>
</template>
<script>
export default {
data() {
let pdfdata = this.$store.getters.pdfData;
return {
data: pdfdata,
pdfsrc: "",
};
},
mounted() {
let da = this.data.reportBase64;
const FILE_NAME = "myCoolFileName.pdf";
const file_header = ";headers=filename%3D";
let datas = "data:application/pdf" + file_header + encodeURIComponent(FILE_NAME) + ";base64," + da;
this.pdfsrc = datas;
},
};
</script>