我使用的是Wintersmith,需要以变量的形式访问location.hash。
这就是我所尝试的,但它产生了一个Cannot read property 'location' of undefined错误:
- var hash = window.location.hash
- var articles = env.helpers.getArticles(contents, hash)
img(data-item = i, src="img/events/"+hash+'/' +a)发布于 2019-01-07 22:01:28
您正在将pug/jade代码与浏览器JavaScript代码混合在一起。Jade/pug在服务器上运行,因此没有可用的"window“变量:
window.location.hash您需要将其作为res.render语句中的变量从路由传入:
res.render('<<viewName>>', { hash: req.query });首先看一下Express req.query docs。
https://stackoverflow.com/questions/54070095
复制相似问题