ES6 In the modularization of ,export And export default Can be used to export constants 、 function 、 file 、 Module etc. , We can do this through other files or modules import( Constant 、 function 、 file 、 modular ) How to import , But in a file or module ,export、import There can be multiple ,export default There is only one .

export Use

1、 Direct output

export let words = 'hello world!!!' export function output() { 
// ... 

2、 First defined in the output

let firstWords = 'hello'let secondWords = 'world'let thirdWords = '!!!'
function output() {
    // ...}
export {firstWords, secondWords, thirdWords, output}

export default Use

1.export default It is used to specify the default external interface of the module

2. Obviously, the default external interface can only have one , therefore  export default Can only appear once in the same module

3.export default It can only output directly , You can't define before you output .

4. Its presence import It's the same way export There is a difference .

(1)export The output of import Input

export function output() {
    // ...
import {output} from './example'

(2)export default The output of import Input

export default function output() {
    // ...
import output from './example'

From the above two import You can see that ,export default Of import The method does not need to use braces to wrap . Because for export default Its output has only one interface , The default interface provided by the module is , Naturally, you don't need to wrap it in braces .