gpt4 book ai didi

javascript - jsPDF AutoTable - autoTable 不是函数

转载 作者:数据小太阳 更新时间:2023-10-29 04:30:45 24 4
gpt4 key购买 nike

我在 Angular 应用程序上使用 JSPdf,我正在尝试使用 JS 自动表插件,但我遇到了 JS 错误

EXCEPTION: Uncaught (in promise): TypeError: doc.autoTable is not a function

TypeError: doc.autoTable is not a function

我通过 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');
}

这里有什么我可能遗漏的吗?或者我可以提供更多代码来帮助确定问题吗?

谢谢!

最佳答案

只需删除 imports 的第一行 2 并添加以下行:

var jsPDF = require('jspdf');
require('jspdf-autotable');

你可以看一个例子here

关于javascript - jsPDF AutoTable - autoTable 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44726278/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com