Okay, so this might seem like a simple question... But I'm new to part of stuff. On http://html2canvas.hertzen.com/getting-started it shows a very small tutorial... When I run npm install -g html2canvas
, it works great. Now comes the part where I'm actually lost. Where do I put the code import html2canvas from 'html2canvas';
? Do I just put this at the top of the javascript file?
import
statement is an ecmascript-6 feature, they are intended to be used at the very top of any Javascript file.
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.
so, in your case simply use import html2canvas from 'html2canvas';
at the top of your file.
However, if you're not using google-chrome or some kind of transpiler ( babel for example), then it won't work , because it's currently not supported in every navigator.
If you're not using a transpiler or google-chrome, think about using requirejs
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.