Skip to content

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

@Dream4ever

Description

@Dream4ever

解决过程

用关键词 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Back-endWhere data really come and go

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions