Can anyone provide guidance on incorporating a vendor library (specifically PDF.js) into a Vue component? I only need to load it for this specific component due to the large file size.
I am working on an editor that requires loading a PDF. I have placed pdf.js and pdf.worker.js in the /src/assets/vendor/pdfjs directory.
Next, I load both files in the template-editor-page.hbs which also loads the component:
<div class="content">
<div class="row fill">
<div class="col-md-2 fill br pt30">
</div>
<div class="col-md-10 fill pt30 pl30 pr30">
<div id="template-editor" class="template-editor">
<template-editor template-src="{{template.src}}"></template-editor>
</div>
</div>
</div>
</div>
<script src="/assets/js/template-editor.bundle.js"></script>
<script src="/assets/vendor/pdfjs/pdf.js"></script>
<script src="/assets/vendor/pdfjs/pdf.worker.js"></script>
In my template-editor.js file (do I need to load it here?):
import Vue from 'vue';
import templateEditor from './components/template-editor.vue';
new Vue({
el: '#template-editor',
components: { templateEditor }
});
Now, I want to use the file in my template-editor.vue:
<template>
<!-- ... -->
</template>
<script>
export default {
props: ['templateSrc'],
name: 'template-editor',
data() {
return {
src: this.templateSrc
};
},
methods: {
render() {
PDFJS.getDocument(this.$data.src).then(function(pdf) {
console.log(pdf);
}, err => console.log(err));
}
},
created: function() {
this.render();
}
};
</script>
However, I encounter an error stating
ReferenceError: PDFJS is not defined
All other aspects are functioning correctly. What could be causing this issue?