Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在uniapp renderjs使用@js-preview/pdf报错window.pdfjsLib未找到 #397

Open
PineSongCN opened this issue Nov 28, 2024 · 0 comments
Open

Comments

@PineSongCN
Copy link

请问是否可以使用cdn的方式引用?
或者如下script加载base64报错 Unexpected token '{' 可能是什么原因导致的?

报错信息

13:35:03.822 Uncaught SyntaxError: Unexpected token '{' at data:text/javascript;base64,dmFyIHQ...省略...YXIoKX19:1
13:35:03.908 发生错误 window.pdfjsLib未找到 at pages/course/detail/components/Courseware/Courseware.vue:28 at uni-app-view.umd.js:7
<script>
export default {
  data() {
    return {
      data: null
    };
  },
  async mounted() {},
  async onShow() {},
  methods: {}
};
</script>

<script module="office" lang="renderjs">
import jsPreviewPdf from "@js-preview/pdf";

// @ts-nocheck
export default {
  data() {
    return {
      pdf:'https://501351981.github.io/vue-office/examples/dist/static/test-files/test.pdf',
    };
  },
  mounted() {
    const myPdfPreviewer = jsPreviewPdf.init(document.getElementById('office-preview'), {
        onError: (e)=>{
            console.log('发生错误', e)
        },
        onRendered: ()=>{
            console.log('渲染完成')
        }
    });
    myPdfPreviewer.preview(this.pdf);

  },
  onunload() {
  },
  methods: {
    emits(key, data){
      this.$ownerInstance.callMethod(key, data);
    },
    initData(data, old, ownerInstance) {
      console.warn('initData', data);
      if (!this.$ownerInstance && ownerInstance) {
        this.$ownerInstance = ownerInstance;
      }
    },
  },
};
</script>

<template>
  <div class="courseware-box">
    <div class="bridge" :data="data" :change:data="office.initData" />
    <div id="office-preview" class="office-preview"></div>
  </div>
</template>

<style lang="scss">
.courseware-box {
  position: relative;
  .bridge {
    position: absolute;
    z-index: -1;
  }
  .vue-office-pdf-wrapper {
    background-color: #fff;
  }
}
</style>

@PineSongCN PineSongCN changed the title 在uniapp renderjs使用报错window.pdfjsLib未找到 在uniapp renderjs使用@js-preview/pdf报错window.pdfjsLib未找到 Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant