The method of loading ES6 module Syntax
This article mainly introduces the relevant knowledge of ES6 module grammar loading method, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this ES6 module grammar loading method article. Let's take a look at it.
Export: to expose is to expose the interface
Import: introduce, literally, introduce an interface
Export {}
Exportfunctiondemo () {}
Exportvardemo1
The two export above can be abbreviated as
Functiondemo () {}
Vardemo1
Export {demo,demo1}
Import {}
Accordingly, of course, there is import.
Import {demo,demo1} from..path
Of course, you can also write another way to write import*asnamefrom..path and then quote it like name.demo ().
Exportdefault
And there is exportdefault.
You can only use exportdefault once in a file.
Exportdefaultfunctiondemo () {}
And then when import
Importdefault
Importname (the name is chosen at random) from..path
See this? no curly braces.
But
Precisely because the exportdefault command actually outputs a variable called default, it cannot be followed by a variable declaration statement.
So exportdefaultvara=1 will report an error if he writes like this!
Vara=1
Exportdefatulta
This is also possible.
A module of export*from
This export* ignores the interface of the output of the module's exportdefault
In that case, does a certain module of import*from fail to import the exportdefault interface defined by the module?
This is the end of this article on "the method of ES6 module Grammar loading". Thank you for reading! I believe you all have a certain understanding of the knowledge of "ES6 module Grammar loading method". If you want to learn more, you are welcome to follow the industry information channel.