亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

Vue-pdf實現在線預覽PDF文件

瀏覽:3日期:2022-09-29 14:02:53
前言

在大多數項目中都會遇到在線預覽PDF文件,項目使用的是element ui,使用vue-pdf實現。

安裝依賴

npm install --save vue-pdf相關參數

參數介紹:

url :pdf 文件的路徑,可以是本地路徑,也可以是在線路徑。 page: 當前顯示的頁數,比如第一頁page=1 rotate : 旋轉角度,比如0就是不旋轉,+90,-90 就是水平旋轉。 progress :當前頁面的加載進度,范圍是0-1 ,等于1的時候代表當前頁已經完全加載完成了。 page-loaded :頁面加載成功的回調函數,不咋能用到。 num-pages :總頁數 error :加載錯誤的回調 link-clicked:單機pdf內的鏈接會觸發。 print 這個是打印函數。 注意:谷歌瀏覽器會出現亂碼,這個和字體有關系。 實現

<template> <div><el-row> <el-button @click='onPreview' size='small'>預覽</el-button></el-row><el-dialog :visible.sync='viewVisible' center @close=’closePreview’> <el-row :gutter='20'><span>共{{pageCount}}頁, 當前第 {{pdfPage}} 頁 </span><el-button type='text' size='mini' @click.stop='previousPage'>上一頁</el-button><el-button type='text' size='mini' @click.stop='nextPage'>下一頁</el-button> </el-row> <div><pdf :src='http://www.aoyou183.cn/bcjs/src' :page='pdfPage' @num-pages='pageCount = $event' @page-loaded='pdfPage = $event' style='display: inline-block; width: 100%'></pdf> </div></el-dialog> </div></template><script>import pdf from ’vue-pdf’import store from ’@/store/’export default { components:{pdf }, data(){return { viewVisible: false, src: null, pdfPage : 1, pageCount: 0, token: store.getters.access_token,} }, methods:{onPreview(){ this.src = pdf.createLoadingTask({url: ’http://localhost:8082/file/demo.pdf’,httpHeaders: {Authorization:’Bearer ’+ this.token} }); this.src.promise.then(pdf => {this.viewVisible = true; });},closePreview(){ this.pdfPage = 1;},previousPage(){ let p = this.pdfPage p = p > 1 ? p-1 : this.pageCount this.pdfPage = p},nextPage(){ let p = this.pdfPage p = p < this.pageCount ? p+1 : 1 this.pdfPage = p} }}</script>效果

Vue-pdf實現在線預覽PDF文件

注意點

1、URL

url為文件地址路徑

this.src = pdf.createLoadingTask({ url: ’http://localhost:8082/file/demo.pdf’,});

2、設置請求頭

可以通過httpHeaders來設置token等參數

httpHeaders: {Authorization:’Bearer ’+ this.token}

3、src

這點比較重要,網上很多帖子都是這樣的

this.src.then(pdf => { this.viewVisible = true;})

會報錯 TypeError: this.src.then is not a function

TypeError: this.src.then is not a function at VueComponent.onPreview (index.vue?6ced:241) at click (index.vue?aaff:261) at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854) at VueComponent.invoker (vue.runtime.esm.js?2b0e:2179) at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854) at VueComponent.Vue.$emit (vue.runtime.esm.js?2b0e:3888) at VueComponent.handleClick (element-ui.common.js?5c96:9413) at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854) at HTMLButtonElement.invoker (vue.runtime.esm.js?2b0e:2179) at HTMLButtonElement.original._wrapper (vue.runtime.esm.js?2b0e:6917)

正確的是這樣的

this.src.promise.then(pdf => { this.viewVisible = true;});

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Vue
相關文章:
主站蜘蛛池模板: 色婷婷综合久久久久中文 | 国产在线ts人妖免费视频 | 特级aa毛片在线播放 | 国产成人久久精品二区三区 | 中国免费一级片 | 国产精品亚洲精品日韩已满 | 欧美日韩综合一区 | 日本成aⅴ人片日本伦 | 国产精品免费大片一区二区 | 日韩成人免费视频播放 | 日韩欧美区 | 成人午夜视频在线观 | 天天狠天天透天干天天怕处 | 欧美成人久久 | 久草热线视频 | 91精品久久一区二区三区 | 色老头福利视频在线观看 | 日本黄色性生活片 | 免费中文字幕一级毛片 | 小明永久免费看aⅴ片 | 久草福利在线播放 | 麻豆国产一区 | 1024你懂的国产欧美日韩在 | 欧美视频黑鬼大战白妞 | 亚洲成在人线av | 中文国产成人精品久久水 | 欧美人成人亚洲专区中文字幕 | 久久青青草原精品无线观看 | 亚洲欧美自拍视频 | 国自产拍在线天天更新2019 | 免费人成网站在线高清 | 成人做爰视频在线观看视频 | 亚洲五月综合缴情婷婷 | 亚洲一欧洲中文字幕在线 | 国产精品夫妇久久 | 在线观看91香蕉国产免费 | ntr中文字幕亚洲综合 | 五月久久噜噜噜色影 | 欧美激情婷婷 | 黑人一区二区 | 色综合综合色综合色综合 |