-
Notifications
You must be signed in to change notification settings - Fork 395
04 如何使用自定义模块
孙正华 edited this page Jul 26, 2018
·
3 revisions
创建自定义模块:
https://github.com/eshengsky/iBlog2/blob/master/utility/tool.js#L2
module.exports = {...}
调用模块:
https://github.com/eshengsky/iBlog2/blob/master/routes/blog.js#L8 https://github.com/eshengsky/iBlog2/blob/master/routes/blog.js#L47
const tool = require('../utility/tool');
...
tool.jsonQuery(categories, { Alias: currentCate });
注意: 导出模块时,可以写成:
module.exports.jsonQuery = function(){}
也可以省略 module,写成
exports.jsonQuery = function(){}
也可以写成
module.exports = function(){}
但不可以写成 exports = function(){}
,即 exports = xxx 时不能省略 module。
如果觉得困惑,可以始终带上 module.
,这样就肯定不会错了。