In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "what are the import methods of es6". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "what are the import methods of es6"!
Methods: 1, all the variables of export in a file are packaged into an object and imported with "import * as from" module "" statement; 2, use "import to name from" module "" statement; 3, use "import {specified name} from" module "" statement.
The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.
Three import methods of es6 import
Import arbitrarily names from "module identifier"
It takes effect only if there is a default exported export default syntax in the module
/ / A.jsexport default 20 from / B.jsimport A from'. / A' the above code takes effect only if there is a default exported export default syntax in A.js. In this case without using {} to reference the module, the naming of the import module is arbitrary, that is, the following three reference names are correct: / / B.jsimport A from'. / A'import B from'. / A'import Something from'. / A' because it always resolves to the default export default in A.js
Import {specify name} from "module identifier"
Takes effect only if there is code in the module that is named and exported to the export name with the specified name
/ / A.jsexport const A = 21//B.jsimport {A} from'. / A' code takes effect only if there is the following code in the module A.js named export name exported as A, and after the named export is explicitly declared, the module naming in import makes sense when you use {} to reference the module in another js. As follows: / / B.jsimport {A} from'. / A'/ / correct, because there is an error in A.js named exportimport {B} from'. / A'/ / error! Because there is no export named B in A.js
Import * as from "module identifier" (wrapped as an object)
Wrap all the variables of export in a file into an object.
For example:
Export const sqrt1 = Math.sqrt;export const sqrt2= Math.sqrt;import * as sqrtobj from ". Sqrtobj.sqrt1sqrtobj.sqrt2 so far, I believe you have a deeper understanding of" what are the import methods of es6? "you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.