首页 > 其他分享 >js之模块导入与导出:export、export default、module.exports、exports

js之模块导入与导出:export、export default、module.exports、exports

时间:2024-05-11 12:53:18浏览次数:12  
标签:exports default 导出 module export import

前两者export、export default可为一组,是es6的规范,和import匹配,import是es6中的语法标准;
后两者module.exports、exports可为一组,是commonjs的规范,和require匹配,require是amd规范下的引入方式。

当组合不适配时,当然就会报错了。

module.exports、exports
1,从使用方式来看,exports是module的一个属性

2,exports默认指向module.exports对象的引用,不能单独给exports赋值,否则无用(改变了exports的指向),引入方什么也拿不到;可给module.exports赋值,或通过module.exports.xx来挂载新属性xx等。

3,不论是module.exports还是exports,向外共享的最终结果是module.exports所指的对象,这两个没什么区别。

4,基于require引入module.exports、exports导出的成员时,括号里的文件不需要带.js,带上也能运行成功。

 

export、export default
1,export和export default都可以用于导出常量,函数,模块,文件等,export default是把此命令后面的变量赋值给default这个特殊的系统变量,并把它导出到其余模块中使用,仅导出模块中一个成员时可使用。

2,以export方式导出时,导入时要加{};以export default导出时,导入时不需要{}

3,export可有多个,export default只能有一个,多个export default会提示TS2528: A module cannot have multiple default exports.

4,用export default导出时的名称可以与引入时的名称不同,但export导出必须和import时名称一致;

5,基于import引入export、export default导出的成员时,from后的文件需要带.js后缀。

标签:exports,default,导出,module,export,import
From: https://www.cnblogs.com/xingxia/p/18186274/js_export_import

相关文章

  • 配置node_exporter
    配置node_exporter配置node_exporter可以通过--web.listen-address和--web.telemetry-path参数来设置端口和路径。例如:node_exporter--web.listen-address=":9600"--web.telemetry-path="/node_metrics"禁用收集器许多收集器默认都是启用的。使用no-前缀来修改状态。例如,......
  • IDEA在运行maven打war的时候报错:Cannot access defaults field of Properties
    问题描述:解决方案在pom.xml文件中引入:<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId>......
  • 应用zabbix的实时导出(real-time export)功能
    说明zabbix作为监控软件,有时也会需要获取历史数据作进一步的分析,通常可以采用3种办法:通过zabbixAPI定期获取(通过web)通过后端数据库定期读取(通过db)应用实时导出功能配合filebeat或其他工具获取(通过server)对比以上三种方法:实时性:毫无疑问,通过实时导出功能将数据发送出去是......
  • vue3项目打包的时候报错'openBlock' is not exported by node_modules/...
    用了一个手写签名的,开发环境中一切正常,但是在打包发布的时候,就报错了。'openBlock'isnotexportedbynode_modules/vue-esign/node_modules/vue/dist/vue.runtime.esm.js.... 这个应该是vue版本重复导致的。 解决:在vite.config.ts中加入 dedupe:['vue'],  dedupe是......
  • export/import
    JavaScript模块的导出与导入:静态特性解析在这篇博客中,我们将探讨JavaScript中的export和import语句的使用,这些语句如何静态地处理代码,以及这种处理方式带来的优势。此外,我们也会探讨不同的函数声明方式,包括匿名函数和具名函数表达式的使用场景和它们的可见性区别。静态导......
  • react报错export ‘Switch‘ (imported as ‘Switch‘) was not found in ‘react-rou
    报如下错,查react-router-dom版本。 因为:react-router-dom从V5升级到V6造成的(1)将Switch重命名为Routes(2)Route的新特性变更,component/render被element替代(3) 嵌套路由变得更简单 ......
  • 3.Exporter概述
    一、Exporter概述    所有可以向Prometheus提供监控样本数据的程序都可以被称为一个Exporter。而Exporter的一个实例称为target,如下所示,Prometheus通过轮询的方式定期从这些target中获取样本数据: 注:安装好Exporter后会暴露一个http://ip:端口/metrics的HTTP服务,通......
  • HINT: It seems you set a fixed date / time / datetime value as default for this
    WARNINGS:customers.PackingHead.packing_date:(fields.W161)Fixeddefaultvalueprovided.HINT:Itseemsyousetafixeddate/time/datetimevalueasdefaultforthisfield.Thismaynotbewhatyouwant.Ifyouwanttohavethecurrentdateasdefault......
  • 性能测试——性能测试-linux监控工具-Centos7.x安装Node_exporter
    参考小菠萝博客笔记:https://www.cnblogs.com/poloyy/p/12375039.html 小菠萝是在一个服务器上面装的,我是2个服务器分别装的,下面需要新增一个命令:useraddprometheus    NODE_PATH='/data/prometheus/node_exporter/'cd/usr/local/src/mkdir-p${NODE_PATH}wget......
  • openGauss Prometheus-Exporter组件命令参考
    命令参考reprocessing-exporter的使用帮助详情:gs_dbmindcomponentreprocessing_exporter--helpusage:[-h][--disable-https][--ssl-keyfileSSL_KEYFILE][--ssl-certfileSSL_CERTFILE][--ssl-ca-fileSSL_CA_FILE][--web.listen-addressWEB.LISTEN_ADDRESS][--web......