需求:簡單說~~有兩個pdf文件需在h6上展示,通過點(diǎn)擊按鈕切換不同文件的顯示
注:
1.vue-pdf默認(rèn)展示首頁,我這里的需求是通過滑動展示所有頁面,這里使用的v-for遍歷。有多少頁就加載了多少個pdf組件。
2.pdf文件存在跨域問題,這個需要后端同學(xué)支持。
3.demo上的pdf文件只有一頁,測試多頁展示,自己改用多頁pdf文件即可
<template> <div class="pdf_wrap"> <div class="pdf_list"> <!-- src:pdf地址,page: 當(dāng)前顯示頁 --> <pdf v-for="i in numPages" :key="i" :src="src" :page="i" > </pdf> </div> <Button type="info" @click="loadPdf(pdfUrl1)"> 文件1 </Button> <Button type="info" native-type="submit" @click="loadPdf(pdfUrl2)"> 文件2 </Button> </div> </template> <script> import pdf from 'vue-pdf' import { Button } from 'vant' export default { components: { pdf, Button }, data () { return { src: '', numPages: undefined, pdfUrl1: 'https://clinic-trial-attachments.oss-cn-beijing.aliyuncs.com/output/demo.pdf/1.pdf', pdfUrl2: '/tupian/20230522/123demo.pdf' } }, mounted () { this.loadPdf(this.pdfUrl1) }, methods: { loadPdf (url) { this.src = pdf.createLoadingTask(url) this.src.promise.then(pdf => { this.numPages = pdf.numPages // 這里拿到當(dāng)前pdf總頁數(shù) }) } } } </script> <style scoped> .pdf_wrap { background: #fff; height: 100vh } .pdf_list { height: 80vh; overflow: scroll; } button { margin-bottom: 20px; } </style>
新聞名稱:vue中使用vue-pdf的方法詳解-創(chuàng)新互聯(lián)
URL分享:http://jinyejixie.com/article24/dpeoje.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、網(wǎng)站營銷、建站公司、品牌網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容