Vue Cli項目使用PDF.js預覽pdf無法訪問到viewer.html


pdf->build,web(viewer)應該放在static

 

pdf組件

<template>
  <view class="content u-padding-0">
    <iframe
      width="100%"
      frameborder="0"
      scrolling="no"
      style="width: 100%; height: 100%; min-height: 450px"
      :src="pdfSrc"
    ></iframe>
  </view>
</template>

<script>
import { mapState, mapMutations } from "vuex";

export default {
  components: {},
  props: {
    src: {
      type: String,
    },
  },
  data() {
    return {
      dataList: [],
      htmlstr1: "",
      pdfSrc: "",
    };
  },
  methods: {
    loadPDF() {
      //pdfSrc :pdf存放的文件路徑,可以是本地的,也可以是遠程,這個是遠程的,親測可以用,用決對路徑避免打包404
      //ie有緩存加個隨機數解決 + '?r=' + new Date()
      // 508257834648080384

      let pSrc = this.src + "?r=" + new Date();
      this.pdfSrc =
        "./static/pdf/web/viewer.html?file=" + encodeURIComponent(pSrc) + ".pdf";
  console.log(this.pdfSrc,"this.pdfSrc")
  },
  },
  mounted: function () {
    this.loadPDF();
  },
};
</script>

<style lang="scss" scoped>
.order {
  /deep/.u-table {
    .u-tr,
    .u-td {
      height: 45px;
      line-height: 45px;
    }
  }
}
</style>

 

引用 

 

 
import mPDF from "./pdf.vue";
 

 <mPDF  v-if="pdfForm.authbook_url"  :src="pdfForm.authbook_url"></mPDF>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM