[英]How to access a JavaScript variable value in pug?
我的index.pug文件如下所示:
head
script(type="text/javascript").
var isMobile = (screen.width || window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) <= 480;
body
if isMobile
include nav_mobile
else
include nav
我写了上面的代码,但没有得到想要的结果。 ( isMobile
似乎总是null
)
如何获取 JavaScript 变量的值以进行 pug?
在呈现该视图的请求处理程序中,您必须传递您希望在视图中访问的变量列表
app.get('/', function (req, res) {
// your code goes here
// you pass each variable in the second parameter to the render method of response object
res.render('index', { isMobile: true });
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.