parent
d97977b0ab
commit
b553ae530a
@ -1,60 +1,60 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<!-- 显示当前页 -->
|
<!-- 显示当前页 -->
|
||||||
<pdf
|
<pdf
|
||||||
v-if="show"
|
v-if="show"
|
||||||
:src="pdfUrl"
|
:src="pdfUrl"
|
||||||
@num-pages="pageCount = $event"
|
@num-pages="pageCount = $event"
|
||||||
@link-clicked="gotoPage($event)"
|
@link-clicked="gotoPage($event)"
|
||||||
style="border: 1px solid black;"
|
style="border: 1px solid black;"
|
||||||
></pdf>
|
></pdf>
|
||||||
|
|
||||||
<!-- 控制按钮 -->
|
<!-- 控制按钮 -->
|
||||||
<button @click="prevPage">上一页</button>
|
<button @click="prevPage">上一页</button>
|
||||||
{{ currentPage }} / {{ pageCount }}
|
{{ currentPage }} / {{ pageCount }}
|
||||||
<button @click="nextPage">下一页</button>
|
<button @click="nextPage">下一页</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import pdf from "vue-pdf";
|
import pdf from "vue-pdf";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
pdf,
|
pdf,
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
show: false, // 是否加载完成
|
||||||
|
pdfUrl: "", // PDF 文件路径
|
||||||
|
currentPage: 1, // 当前页码
|
||||||
|
pageCount: 0, // 总页数
|
||||||
|
};
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.loadPdf();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
loadPdf() {
|
||||||
|
// 设置 PDF 路径
|
||||||
|
this.pdfUrl = "pdf/模板.pdf";
|
||||||
|
this.show = true;
|
||||||
},
|
},
|
||||||
data() {
|
gotoPage(pageNumber) {
|
||||||
return {
|
if (pageNumber >= 1 && pageNumber <= this.pageCount) {
|
||||||
show: false, // 是否加载完成
|
this.currentPage = pageNumber;
|
||||||
pdfUrl: "", // PDF 文件路径
|
}
|
||||||
currentPage: 1, // 当前页码
|
|
||||||
pageCount: 0, // 总页数
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
mounted() {
|
prevPage() {
|
||||||
this.loadPdf();
|
if (this.currentPage > 1) {
|
||||||
|
this.currentPage--;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
nextPage() {
|
||||||
loadPdf() {
|
if (this.currentPage < this.pageCount) {
|
||||||
// 设置 PDF 路径
|
this.currentPage++;
|
||||||
this.pdfUrl = "pdf/模板.pdf";
|
}
|
||||||
this.show = true;
|
|
||||||
},
|
|
||||||
gotoPage(pageNumber) {
|
|
||||||
if (pageNumber >= 1 && pageNumber <= this.pageCount) {
|
|
||||||
this.currentPage = pageNumber;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
prevPage() {
|
|
||||||
if (this.currentPage > 1) {
|
|
||||||
this.currentPage--;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
nextPage() {
|
|
||||||
if (this.currentPage < this.pageCount) {
|
|
||||||
this.currentPage++;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
</script>
|
};
|
||||||
|
</script>
|
Loading…
Reference in new issue