I have a very simple implementation of jsPDF in a react project I'm currently working on.(在我目前正在从事的React项目中,我有一个非常简单的jsPDF实现。)
Just trying to run the sample 'hello world' code but the save method throws the following error:(只是尝试运行示例“ hello world”代码,但save方法会引发以下错误:)
My code is very simple, first, import the lib like this:(我的代码非常简单,首先,像这样导入lib:)
import jsPDF from 'jspdf';
Then on a click event function from a Component(然后从组件单击事件功能)
<IOControls exportDrawing={this.exportDrawing} />
I run:(我跑:)
exportDrawing() {
const doc = new jsPDF();
doc.text('Hello World!', 10, 10);
console.log(doc); // shows an object
doc.save('a4.pdf');
}
The above error triggers on save() but I have no idea what exactly is causing it.(上面的错误在save()上触发,但我不知道到底是什么原因引起的。)
Any help will be much appreciated.(任何帮助都感激不尽。)
UPDATE I just noticed that if I call the methods at the root of my app component the code works fine, the problem ocurrs when it is called from within other components.(UPDATE我刚刚注意到,如果我在我的应用程序组件的根目录中调用方法,则代码可以正常工作,当从其他组件中调用它时,就会出现问题。)
Here is my setup(这是我的设置)
<App>
<Sketch>
<SketchControls>
<IOControls>
exportDrawing()
is declared in <Sketch>
and the its triggered from a button in <IOControls>
(在<Sketch>
声明exportDrawing()
,并通过<IOControls>
的按钮触发它)
ask by Ricardo Sanchez translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…