// Basic knowledge of a module/*** export: used to export the module * import: file import entry * // 1, first, use the export method to output var A = 'a'; var B = 'V'; export {a, B}; // 2, use export as the default output export {A as streamv1, B as streamv2}; // 3. The export can be at any position, as long as it is at the top, cannot be in block-level scope/*** import file module loading * // 1. Directly load import {a, B} from 'in the module '. /ass '; // 2. The module outputs import * as cricle from' directly '. /ass 'cricle. A // A/*** export default output command, import module loading, no {} module loading ** // 1. Anonymous functions are directly used, import can be directly loaded by the module, and the output name export default function () {console. log ('foo');} import customname from '. /export-default '; // 2, directly output function add (x, y) {return x * Y ;}
Export {Add as default} // directly equivalent to export default add;
Import {default as Foo} from '. /add'; import Foo from '. /modules '/*** combination of export and import */export {Foo, bar} from '. /my_module '; // It can be simply understood as import {Foo, bar} from '. /my_module '; export {Foo, bar}; // 2. Export List export {detectcats, kittydar}; // No 'export' keyword required here function detectcats (canvas, options) {...} class kittydar {...} // 3. Rename Export and Import {flip as flipomelet} from "eggs. JS "; import {flip as fliphouse} from" real-estate.js"
Function V1 () {...} function V2 (){...}
Export {v1 as streamv1, v2 as streamv2, v2 as streamlatestversion}; // 4. Default Import and Export
Import colors from "Colors/safe"; export default {field1: value1, field2: value2 };
// Module object, such as namespace
Import * as cows from "cows ";
// The aggregation module. It does not bind the export {tea, cinnamon} from "Sri-Lanka" variable to be exported to the current scope ";
/*** Understanding es6 module mechanism https://zhuanlan.zhihu.com/p/33843378? Group_id = 947910338939686912 */
Basic es module knowledge, deep understanding