Node.js Express 3.x 将变量传递给 View

标签 node.js templates views express

您可以使用以下方法向 View 公开数据:app.local 和 res.locals。有人确切知道两者之间的区别是什么吗?谢谢

最佳答案

来自 express.js API 文档:

应用本地化

Application local variables are provided to all templates rendered within the application. This is useful for providing helper functions to templates, as well as app-level data.

资源本地化

Response local variables are scoped to the request, thus only available to the view(s) rendered during that request / response cycle, if any. Otherwise this API is identical to app.locals.

这意味着唯一的区别是 res.locals 仅在请求的生命周期内有效。

关于Node.js Express 3.x 将变量传递给 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11770425/

相关文章:

javascript - window.postMessage 在 React 中没有 setTimeOut 的情况下无法在 componentDidMount 中工作

c# - 使用 SqlConnection.GetSchema 仅获取表(无 View )

c++ - 从模板化类中删除模板类型

具有动态回调函数类型的 C++ 模板类

c++ - 使用继承时未解析的引用

google-bigquery - bigquery 备份所有 View 定义

mysql - 处理 View 的 MySQL 临时表算法

javascript - 所有 npm 命令都给出相同的错误 (ENOENT)

node.js - 复合服务器 8888 失败并显示 "failed to connect to [localhost:27017]"

node.js - Reddit api session cookie 格式?