You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.2 KiB

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