我在互联网上搜索了所有内容,但一无所获。我知道这是一个菜鸟问题。
我在 vue 项目中通过 npm 安装了 jspdf 和 jspdf-autotable:
npm install jspdf --save
npm install jspdf-autotables --save
已成功安装包。我正在main.js文件中导入jspdf和jspdf-autotable,如下所示:
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');
但不会导入自动表。它说未解析的方法或钩子自动表。我得到空的pdf。
我不知道如何导入自动表。请帮助我。我的工作还剩一天。对不起,我是 Vue js 的新手。提前非常感谢!
好问题,但没有必要在主文件中使用它,您可以在特定文件中使用它(出于性能原因(。自动表是在 JsPDF 中使用表格的一种补充。这只需要在组件中加载文件。 例如:
import JsPDFAutotable from 'jspdf-autotable'
和您的组件
components: { JsPDFAutotable }
您不需要在main.js文件中导入。
您是否直接在 .vue 文件中导入。 效果很好。
import jsPDF from 'jspdf'
import 'jspdf-autotable'
然后在mounted((钩子中:
let doc = new jsPDF();
doc.autoTable({ html: '#my-table' });
doc.save('table.pdf');