Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to export the module of es6

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge of this article "how to export the module of es6", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to export the module of es6" article.

Es6 module export using the method: 1, export the default module, a module file can only have one default module, syntax for "export default needs to export members"; 2, export ordinary module, a module file can have multiple ordinary modules, syntax for "export on-demand export members".

This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.

What method is used for module export of es6

Default export

A module file can only have one default module, and can have multiple normal modules

Statement: members to be exported by export default

Const N1 = 10const N2 = 20 const show = () = > {console.log ('hello')} export default {N1, show}

Default import

Statement: the name of the import variable from 'module identifier'

Import M1 from'. / 1. Export .js' console.log (M1) by default

Note:

Only one export default is allowed in each module, otherwise an error will be reported!

The default receive name on import can be any name, as long as it is a valid member name

Export on demand

Any data type can be exported as a module

Syntax: on-demand exported syntax: export on-demand exported members

Export const N1 = 10 export const N2 = 20

Import on demand

Syntax for on-demand import: import {M1} from 'module identifier'

Import {N1} from'. / 3. Export .js' console.log (N1) on demand

Considerations for on-demand import and export:

Multiple on-demand exports can be used in each module

The member name imported on demand must be consistent with the name exported on demand

When importing on demand, you can rename it using the as keyword

On-demand imports can be used with default imports

The above is about the content of this article on "how to export the module of es6". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report