[英]jsPDF-AutoTable " doc.autoTable is not a function"
[英]jsPDF AutoTable - autoTable is not a function
我在 Angular 应用程序上使用 JSPdf,我正在尝试使用 JS 自动表插件,但我遇到了 JS 错误
例外:未捕获(承诺):TypeError:doc.autoTable 不是函数
类型错误: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');
}
有什么我可以在这里遗漏的或者我可以提供更多代码来帮助确定问题吗?
谢谢!
我遇到了同样的问题,我像这样修复了它:
import jsPDF from '../../node_modules/jspdf/dist/jspdf.umd.min.js'
import { applyPlugin } from 'jspdf-autotable'
applyPlugin(jsPDF)
我用 "jspdf": "^2.3.1", "jspdf-autotable": "^3.5.20" 希望对你有帮助!
我遇到了同样的问题,这对我有用。 我把它写在导入中
import * as jsPDF from 'jspdf';
import 'jspdf-autotable';
在函数中我将其声明为
const doc = new jsPDF();
我今天在使用https://github.com/SimulatedGREG/electron-vue时遇到了同样的问题。 我通过将“jspdf”和“jspdf-autotable”添加到 path-to-project/.vscode 中的白名单数组来解决它
let whiteListedModules = [
'vue',
'vue-sweetalert2',
'element-ui',
'vue-avatar-component',
'vue-router',
'vue-json-excel',
'vuex',
'vue-chart-js',
'pluralize',
'Print',
'jspdf',
"jspdf-autotable"
]
您可以将 jsPDF 作为正常导入的方式导入:
import jsPDF from 'jspdf';
然后对于 autoTable :
require('jspdf-autotable');
在函数中添加这个 ^
这对我有用:
import jsPDF from 'jspdf';
require('jspdf-autotable');
const tableColumns = ["column1", "Column2", "Column3"];
const tableRows = [[1,2,3],[a,b,c],[X,Y,Z]];
const doc = new jsPDF();
doc.autoTable(tableColumns, tableRows, { startY: 20 });
doc.text("Closed tickets within the last one month.", 14, 15);
doc.save('dataModel.pdf');
import jsPDF from 'jspdf';
import autoTable from 'jspdf-autotable';
const doc = new jsPDF();
autoTable(doc, { html: '#my-table' });
doc.save('table.pdf');`
这对我有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.