Skip to content

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

Open
@PineSongCN

Description

@PineSongCN

请问是否可以使用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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions