好吧,所以这看起来像是一个简单的问题......
但我对某些东西不熟悉。在 http://html2canvas.hertzen.com/getting-started它显示了一个非常小的教程......
当我运行 npm install -g html2canvas
时,效果很好。
现在是我真正迷路的部分。将代码 import html2canvas from 'html2canvas';
放在哪里?
我只是把它放在 javascript 文件的顶部吗?
最佳答案
import
语句是一个 ecmascript-6功能,它们旨在用于任何 Javascript 文件的最顶部。
The import statement is used to import bindings which are exported by another module. Imported modules are in strict mode whether you declare them as such or not. The import statement cannot be used in embedded scripts.
因此,在您的情况下,只需在文件顶部使用 import html2canvas from 'html2canvas';
。
但是,如果您没有使用 google-chrome或某种转译器(例如 babel),then it won't work ,因为目前并非每个导航器都支持它。
如果您不使用转译器或 google-chrome,请考虑使用 requirejs
关于javascript - 如何开始使用 html2canvas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50293693/