我在Angular应用程序上使用JSPdf,我正在尝试使用JS autotable插件,但我遇到了JS错误
EXCEPTION:Uncaught(承诺):TypeError:doc.autoTable不是函数TypeError:doc.autoTable不是函数
我通过npm安装了jspdf和jspdf-autotable,我确认它们在节点模块中 .
我用这种方式导入了两个插件:
import * as jsPDF from 'jspdf'
import * as autoTable from 'jspdf-autotable'
这是我的代码:
private renderPdf():void{
let testcolumns = ["TestCol1", "TestCol2"];
let testrows = [["test item 1", "test item 2"]];
let doc = new jsPDF();
doc.autoTable(testcolumns, testrows);
doc.save('sample.pdf');
}
我可以在这里找到什么或者我可以提供更多代码来帮助确定问题吗?
谢谢!
2 回答
只需删除第2行导入并添加以下行:
你可以看一个例子here
我在使用https://github.com/SimulatedGREG/electron-vue时遇到了同样的问题 . 我通过在路径到项目/ .vscode的白名单数组中添加'jspdf'和'jspdf-autotable'来解决它