1、依赖
"vue-pdf": "^4.2.0",
"pdfjs-dist": "^2.5.207",
2、实现
<pdf :src="pdfUrl" ref="pdf" v-for="i in numPages" :key="i" :page="i" />
import pdf from "vue-pdf";
data() {
return {
pdfUrl: "",
numPages: 0,
totalPages: 0,
};
}
fun getData(){
let fileBlob = that.base64ToBlob(datas.row, "application/pdf");
that.pdfUrl = window.URL.createObjectURL(fileBlob);
let loadingTask = pdf.createLoadingTask(that.pdfUrl);
loadingTask.promise.then((pdf) => {
that.totalPages = pdf.numPages;
console.log(this.numPages)
}).catch((err) => {
console.error("pdf 加载失败", err);
});
//定时器解决报错Rendering cancelled
var timer = setInterval(() => {
that.numPages += 1
if (t