请教:nodeclub视图文件里的local是什么?
发布于 10 年前 作者 xyz2k8 3752 次浏览 最后一次编辑是 8 年前

nodeclub视图文件里的local是什么?是怎么传到视图的?

3 回复

这些都是自动的吗?我搜索代码没看到有如下类似的代码:

app.use(function(req, res, next){ res.locals.user = req.user; res.locals.authenticated = ! req.user.anonymous; next(); });

当然,我指的不仅仅是locals.user,代码中还有很多,比如:locals.edit_error…

服务端:res.render(‘book/book’,{bookInfo:bookinfo,authorInfo:authorinfo,bookChapter:bookchapter, bookSimiler:booksimiler,bookRecommends:bookrecommends});

web 页面: <% if(locals.bookInfo ) { %> <a href="/chapindex/<%= bookInfo._id %>/1" > <% } %>

这里web页面的 locals.bookInfo 对应 服务端的 bookInfo

回到顶部