Home  >  Article  >  Web Front-end  >  ES6 module syntax loading import export

ES6 module syntax loading import export

php中世界最好的语言
php中世界最好的语言Original
2018-02-24 09:55:5114977browse

This time I bring you ES6 module syntax loading import export, ES6 module syntax loading import export What are the precautions, the following is a practical case, let's take a look.

export: exposure, that is, exposing the interface

import: introduction, just like the literal meaning, introduce the interface

export {}
export function demo(){}
export var demo1;

The two above Export can be abbreviated as

function demo(){}
var demo1;
export {demo, demo1}
import {}

Correspondingly, of course there is import

import {demo,demo1} from ..path

Of course, you can also write another way of writing import * as name from ..path Then when refers to , it is name.demo() like this

export default

And there is export default

A file can only be used once export default

export default function demo(){}

Then when importing

import default

import name(this The name is just chosen by me.) from ..path

I don’t see this without curly brackets

But

It’s precisely because the export default command actually only outputs a file called default variable, so it cannot be followed by a variable declaration statement.

So if export default var a=1 is written like this, an error will be reported! ! ! ! !

var a=1;

export defatult a ;

This is also possible

export * from a certain module

this export* will ignore the interface output by the export default of the module

If you say this, import * from a certain module will not be able to import the export default interface defined by the module

I believe it will take a look After reading these cases, you have mastered the methods. For more exciting information, please pay attention to php Chinese websiteOther related articles!

Related reading:

How to make copyright symbols more beautiful in HTML

html Jump to other pages in two seconds

What should you pay attention to about centering elements in HTML

The above is the detailed content of ES6 module syntax loading import export. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn