在VUE的开发构建中使用导入的脚本
我目前正在构建一个应用程序,并且仅通过脚本在一个页面中仅应用于VUE 3。
<script src="https://unpkg.com/jspdf@latest/dist/jspdf.umd.min.js"></script>
<script src="https://unpkg.com/vue@3"></script>
我正在尝试通过脚本使用导入的模块(JSPDF),但它不起作用。
methods: {
generateReport() {
let pdfName = 'test';
var doc = new jsPDF();
doc.text("Hello World", 10, 10);
doc.save(pdfName + '.pdf');
}
}
当我尝试执行上述方法时,这是错误:
Uncaught ReferenceError: jsPDF is not defined
是否可以在VUE的开发构建中使用使用脚本导入的模块?还是在不导入脚本的情况下生成PDF的其他方法?
I'm currently building an application and, and I applied vue 3 only in one page via script.
<script src="https://unpkg.com/jspdf@latest/dist/jspdf.umd.min.js"></script>
<script src="https://unpkg.com/vue@3"></script>
I'm trying to use the imported module (jsPdf) via a script, and it is not working.
methods: {
generateReport() {
let pdfName = 'test';
var doc = new jsPDF();
doc.text("Hello World", 10, 10);
doc.save(pdfName + '.pdf');
}
}
This is the error when I'm trying to do the method above:
Uncaught ReferenceError: jsPDF is not defined
Is it possible to use the module imported using script in the development build of Vue? or is there any other way to generate pdf without importing scripts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试喜欢片段
Try like following snippet
您是否在要使用它的.vue文件中导入库?
来自“ JSPDF”的导入{JSPDF};
Have you imported the library in the .vue file you are trying to use it in?
import { jsPDF } from "jspdf";