转载:http://blog.csdn.net/zhou_xiao_cheng/article/details/52759632

本文原创地址链接:http://blog.csdn.net/zhou_xiao_cheng/article/details/52759632,未经博主允许不得转载。

export与export default exports与module.exports的用法

-------------------------------------------------------
// export
export function tt(tagName, attrs, children) {
return new Element(tagName, attrs, children)
}
export const aa = '123';

// 引用
import { tt,aa } from 'aa'
-------------------------------------------------------
// export default 导出只能有一个
export default const str = 'hello world';
export default function tt {
console.log("hello world")
}

// 引用的时候就不用中括号了
import aa from 'demo1'

// 也可以不用函数名字,因为在js中,下边这两个达到同样的效果
var ss = function () {}
var ss = function ss1() {}

-------------------------------------------------------
// module.exports 同一下的exports

-------------------------------------------------------
// exports
exports.findNodeById = findNodeById;
exports.deepCopy = deepCopy
exports.treeRecursion = treeRecursion;
或者
exports = {
aa: 123,
bb:function(){}
}
// 引用
import recursion from '@/commons/js/recursion.js'
this.leafNode = recursion.treeRecursion(result,[]);
-------------------------------------------------------
如果同时在代码中导出module.exports 和exports的话。而模块导出的时候,真正导出的执行是module.exports,而不是exports

看到这里,相信大家都看到答案了,exports是引用 module.exports的值。module.exports 被改变的时候,exports不会被改变,而模块导出的时候,真正导出的执行是module.exports,而不是exports

再看看下面例子

// foo.js
exports.a = function(){
console.log('a')
}
module.exports = {a: 2}
exports.a = 1
// test.js
var x = require('./foo');
console.log(x.a)
result:
2

export与export default exports与module.exports的用法的更多相关文章

  1. exports与module.exports,export与export default 之间的关系和区别

    首先我们要明白一个前提,CommonJS模块规范和ES6模块规范完全是两种不同的概念. CommonJS模块规范 Node应用由模块组成,采用CommonJS模块规范. 根据这个规范,每个文件就是一个 ...

  2. exports、module.exports 和 export、export default

    先了解他们的使用范围. require: node 和 es6 都支持的引入export / import : 只有es6 支持的导出引入module.exports / exports: 只有 no ...

  3. NodeJS的exports、module.exports与ES6的export、export default深入详解

    前言 决定开始重新规范的学习一下node编程.但是引入模块我看到用 require的方式,再联想到咱们的ES6各种export .export default. 阿西吧,头都大了.... 头大完了,那 ...

  4. exports与module.exports的区别,export与export.defult区别

    在JS模块化编程中,之前使用的是require.js或者sea.js.随着前端工程化工具webpack的推出,使得前端js可以使用CommonJS模块标准或者使用ES6 moduel特性. 在Comm ...

  5. exports与module.exports的区别,以及export与export.defult的区别

    在 JS 模块化编程的模块引入上, 主要有两种方式: CommonJS 模块标准 ES6 moduel 特性 1. CommonJS 模块引入:require() 模块导出:exports 或者 mo ...

  6. exports 和 module.exports

    首先参考一个js的示例 app.js var a = {name: 'nswbmw 1'}; var b = a; console.log(a); console.log(b); b.name = ' ...

  7. Node.js之exports与module.exports

    每一个node.js执行文件,都自动创建一个module对象,同时,module对象会创建一个叫exports的属性,初始化的值是 {} module.exports = {}; Node.js为了方 ...

  8. Node.js中exports,module.exports以及require方法

    在Node.js中,使用module.exports.f = ...与使用exports.f = ...是一样的,此时exports就是module.exports的一种简写方式.但是,需要注意的是, ...

  9. exports 与 module.exports 的区别

    exports与module.exports的作用就是将方法或者是变量暴露出去,以便给其他模块调用,再直接点,就是给其他模块通过require()的方式引用. 那么require()一个模块时,到底做 ...

随机推荐

  1. FRM-40212: Invalid value for field %s.

    Cause:        Caused by one of the following: 1.  The value is not of the proper data type. 字段类型不对 2 ...

  2. 174. Dungeon Game(动态规划)

    The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...

  3. 数据仓库基础(三)OLAP

    本文转载自:http://www.cnblogs.com/evencao/archive/2013/06/14/3135589.html 联机处理分析(OLAP):介绍 首先要理解的概念: 1.维度: ...

  4. kafka监控工具

    Kafka Web Conslole Kafka Manager KafkaOffsetMonitor.

  5. 蓝牙协议 HFP,HSP,A2DP,A2DP_CT,A2DP_TG,AVRCP,OPP,PBAP,SPP,FTP,TP,DTMF,DUN,SDP

    简介: HSP(手机规格)– 提供手机(移动电话)与耳机之间通信所需的基本功能. HFP(免提规格)– 在 HSP 的基础上增加了某些扩展功能,原来只用于从固定车载免提装置来控制移动电话. A2DP( ...

  6. 重启eclips后启动项目出现监听文件找不到

    重启eclips后启动项目出现监听文件找不到 问题: 重启eclips后启动项目出现Error configuring application listener of class com.thinkg ...

  7. 在ubuntu英文系统下使用中文输入法

    How to install and use Chinese Input Method in the English Locale in Ubuntu ?(1) Check if there exis ...

  8. TI 实时操作系统SYS/BIOS使用总结

    1:概述: SYS/BIOS 是一个可扩展的实时的操作系统.具有非常快速的响应时间(在中断和任务切换时达到较短的延迟),响应时间的确定性,强壮的抢占系统,优化的内存分配和堆栈管理(尽量少的消耗和碎片) ...

  9. vs2012旗舰版 有效注册密钥

    Microsoft Visual Studio Ultimate 2012 旗舰版 有效注册密钥: YKCW6-BPFPF-BT8C9-7DCTH-QXGWC

  10. ubuntu下安装mkfs.jffs工具

    一.环境 Os: ubuntu 16.04 二.安装 2.1安装依赖库 sudo apt install zlib1g-dev liblzo2-dev uuid-dev 2.2编译安装mtd-util ...