调用路由时,变量如何传输
发布于 12 年前 作者 sunuxreg 3564 次预览 最后一次回复是 12 年前 来自
在app.js中如果有var test=123;然后调用路由app.get(’/’,routes.index);那么,如何在routes.js中获得app.js中的test变量呢?因为test不是req的一部分,不能通过req[’ ‘]的形式访问啊。我试过app.get(’/’,routes.index,{test=123});也是不行的。
1 回复
在app.js中如果有var test=123;然后调用路由app.get(’/’,routes.index);那么,如何在routes.js中获得app.js中的test变量呢?因为test不是req的一部分,不能通过req[’ ‘]的形式访问啊。我试过app.get(’/’,routes.index,{test=123});也是不行的。
如下:
然后在routes.index里就可以通过
req.test取出值来了