export

Export has two export modes, export and export default(there can only be one default in a module)

Export can be followed by a variable declaration expression or an {} containing the variable name, but cannot directly output a variable

Export default can be directly followed by a constant or variable, but not by a declared expression

Export variables

Export var name = 'caw' const age = 18 export {age} const sex = 'female' export default {sex} // Default var name=' ABC '// ErrorCopy the code

The export function

Both export and export can directly export function declarations, but export cannot be followed by an anonymous function. If the function name export is directly exported, it needs to be wrapped with {}

Export default function fn1 () {console.log('fn function')} export function fn2 () {console.log('fn2 function')} Function fn3 () {console.log('fn3 function')} export {fn3} export function () {console.log('test function') }Copy the code

The import and export of default

export default function fn1 () {
  console.log('fn1 function')
}
Copy the code

Import direct import

import fn1 from './common'
fn1();
Copy the code

Importing through deconstruction should not cause errors

import {fn1} from './common'
fn1();
Copy the code

Export the default summary

This keyword exports values, which can be received using any variable when importing

The import and export

Export const fn1 = () => {console.log(' console.log ')} export function fn2 () {console.log(' console.log ')} import {fn1,fn2} from './common' fn1() fn2()Copy the code

Export summary

Export exports them in an object, then exports the object, and import deconstructs each property/method

export default + export

Export const fn1 = () => {console.log(' console.log ')} export function fn2 () {console.log(' console.log ')} const defaultFunc = () Log ('defaultFunc executed ')} export default defaultFunc import defaultFunc, {fn1, fn2} from './common' // importCopy the code

This article is based on a great bull’s article