0

我使用 Koa 中间件,在某些代码中我在路由器中使用此代码:

module.exports = ({router}) => {
//some code
}

如果我做:

module.exports = {router} => {
//some code
}

nodejs 应用程序引发错误。那么除了错误部分之外,这两个不同的导出之间有什么区别?

4

1 回答 1

0

{(router)} 是错误的。您应该将 module.exports 视为一个函数,因此它具有 () 参数所在的位置,在这种情况下,它是您要导出的函数的对象 {}(这里是路由器,但它也可以是多个。

我认为这篇文章给出了非常清楚的解释:https ://www.sitepoint.com/understanding-module-exports-exports-node-js/

于 2019-09-11T19:23:11.757 回答