我找遍了互联网,但什么也没找到。我知道这是个菜鸟问题。
我在我的vue项目中通过npm安装了jspdf和jspdf-autotable:
npm install jspdf --save
npm install jspdf-autotables --save已成功安装程序包。我将jspdf和jspdf-autotable导入到main.js文件中,如下所示:
import jsPDF from 'jspdf';
import 'jspdf-autotable';
Vue.use(jsPDF)然后在我的.vue文件中,我首先导入jsPDF:
import jsPDF from 'jspdf';然后在mounted()钩子中:
let doc = new jsPDF();
doc.autoTable({ html: '#my-table' });
doc.save('table.pdf');但不导入autoTable。它显示未解析的方法或钩子自动。我得到的是空的pdf。
我不知道如何导入autoTable。请帮帮我。还有一天就要完成我的工作了。抱歉,我是Vue js的新手。首先要感谢大家!
发布于 2020-01-17 01:51:44
问得好,但没有必要在你的主文件中使用它,你可以在你的特定文件中使用它(出于性能原因)。autotable是在JsPdf中使用表格的一个补充。这只需要在您的组件中加载文件。例如:
import JsPDFAutotable from 'jspdf-autotable' 和您的组件
components: { JsPDFAutotable }发布于 2020-02-20 02:08:56
您不需要main.js文件中的导入。
是否直接在.vue文件中导入。这很好用。
import jsPDF from 'jspdf'
import 'jspdf-autotable'然后在mounted()钩子中:
let doc = new jsPDF();
doc.autoTable({ html: '#my-table' });
doc.save('table.pdf');https://stackoverflow.com/questions/59112533
复制相似问题