zoukankan      html  css  js  c++  java
  • ES6中export及export default的区别

          在ES6中,export和export default均可用于导出常量、函数、文件、模块等,你可以在其他文件或模块中通过import + (常量 | 函数 | 文件 | 模块)名的方式将其导入,以便能够对其进行使用,但在一个文件或模块中,export、import可以有多个,export default仅有一个。

    具体使用:

    // 1、demo1.js
    export const str = 'hello word'
    
    export function f(a) {
      return a+1  
    }
    

      对应的导入方式:

    // demo2.js
    import {str, f} from 'demo1'  // 也可以分开写两次,导入的时候带括号
    

      

    // 2、demo1.js
    export default const str = 'hello word'
    

      对应的导入方式

    // demo2.js
    import str from 'demo1'  // 导入的时候没有花括号
    

      

  • 相关阅读:
    异常处理
    集合面试题
    数据结构
    集合遍历
    集合汇总
    Collections工具类
    HashMap和hashTable的区别
    Map接口和Collection接口的区别
    Spark应用远程调试
    使用 maskView 设计动画
  • 原文地址:https://www.cnblogs.com/carriezhao/p/8179681.html
Copyright © 2011-2022 走看看