使用 Node 写一个网站的时候,需要把 sidebar,footer 等公共部分作为单独文件独立出来,在其他页面使用 include 形式加载。那么这些模板在其他页面加载时数据怎么传进去比较方便,每一个页面都需要查询一遍吗?有没有比较简单的方案呢?
回复 (4)
C
常量啊
A
引用 captainblue2013常量啊
@captainblue2013 你是说 app.locals 还是 res.locals,怎么更新呢
M
locals > res.locals > app.locals a > b 表示 a覆盖b
see https://github.com/strongloop/express/blob/4.13.3/lib/application.js#L545 https://github.com/strongloop/express/blob/4.13.3/lib%2Fresponse.js#L952
C
参与回复
登录后即可参与回复。登录