In es6, import is used to load another module containing an export interface in a module; after using the export command to define the external interface of the module, the JS file can load the module through the import command. The syntax is: "import export module interface from js file".
The operating environment of this tutorial: Windows 10 system, ECMAScript version 6.0, Dell G3 computer.
ES6 module mainly has two functions: export and import
export is used to output this module externally (a file can be understood as a Module) variable interface
import is used to load another module containing an export interface in a module.
That is to say, after using the export command to define the external interface of the module, other JS files can load this module (file) through the import command.
As shown below (assuming files a and b are in the same directory)
a.js file can also be pressed The export syntax is written as follows, but it is not as intuitive as the above and is not recommended.
// a.js export var sex="boy";export var echo=function(value){ console.log(value) } //因为function echo(){}等价于 var echo=function(){}所以也可以写成 export function echo(value){ console.log(value) }
[Related recommendations: javascript video tutorial, web front-end】
The above is the detailed content of What is the usage of import in es6. For more information, please follow other related articles on the PHP Chinese website!