ES6 export default function

前端 未结 3 770
臣服心动
臣服心动 2021-02-04 03:46

can I export more than one function per file ? it seems like when I do that , the second function ovverides the first one ,

example : in my index.js file

3条回答
  •  一向
    一向 (楼主)
    2021-02-04 04:36

    madox2's answer totally works if you want to import named functions.

    If you still want to import the default, there's another technique:

    function a() {}
    
    function b() {}
    
    export default { a, b }
    

    and when you import:

    import myObject from './index.js';
    
    myObject.a(); // function a
    myObject.b(); // function b
    

    I hope this helps!

提交回复
热议问题