Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.4k views
in Technique[技术] by (71.8m points)

vue可以引入本地的pdf文件吗?现在引入直接报404

报错
image.png

路径打印出来和点进去
image.png
image.png

报错点进去
image.png

插件用了vue-pdf,项目用了proxy转地址,走地址时跑到了后台路径。
我现在想实现的是引入本地项目public文件夹下的pdf文件,不走后台路径。

走地址直接走成这个了
image.png

<pdf
    v-for="i in numPages"
    :key="i"
    :src="src"
    :page="i"
    @page-loaded="pageLoaded($event)"
  ></pdf>
  
 
 
  data() {
    return {
      visible: false,
      currentPage: 0,
      pageCount: 0,
      src: '',
      // src: loadingTask,
      numPages: undefined, // 总页数
      curPageNum: 0, //当前页
    };
  },
  mounted() {
    let that = this,
        url = `http://127.0.1.1:8383${path.resolve(__dirname,'../assets/pdf/pdf.pdf')}`;
    that.src = pdf.createLoadingTask(url); // url是pdf文件的全路径
    console.log(url)
    // that.src.promise.then(pdf => {
    //   that.numPages = pdf.numPages;
    // });
  },

image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
/assets/pdf/pdf.pdf

你的这个地址是在 public 下面吗?
我记得这个 assets 都是在 src 下面,打包后路径就变了。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...