Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Express.js 中间件向下一个函数传递值 #193

Closed
Dream4ever opened this issue May 9, 2022 · 0 comments
Closed

Express.js 中间件向下一个函数传递值 #193

Dream4ever opened this issue May 9, 2022 · 0 comments
Labels
Back-end Where data really come and go

Comments

@Dream4ever
Copy link
Owner

解决过程

用关键词 express.js middleware pass data to next Google,找到答案:Passing variables to the next middleware using next() in Express.js

简单来说,就是在中间件里把需要传递的值放到 res.locals 中,比如 res.locals.varr = varr,然后在下一个函数里就可以通过 res.locals.varr 来调用了。

官方文档:res.locals

@Dream4ever Dream4ever added the Back-end Where data really come and go label May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Back-end Where data really come and go
Projects
None yet
Development

No branches or pull requests

1 participant