[英]how to render JavaScript using pug/jade
For example, I pass a user
variable to this pug file, and I want to run some js code after dom has loaded. 例如,我将
user
变量传递给此pug文件,并且我想在dom加载后运行一些js代码。
script.
document.addEventListener("DOMContentLoaded", function(event) {
console.log(#{user.name});//log the user's name
});
Is it possible to do so? 有可能这样做吗?
First, you're trying to use a string interpolation #{user.name}
outside of a string. 首先,您尝试在字符串外部使用字符串插值
#{user.name}
。 Use !{user.name}
instead for unescaped code interpolation. 使用
!{user.name}
代替未转义的代码插值。 If you need this to be in a string you'll need to surround the variable in quotes as well. 如果您需要将其包含在字符串中,则还需要将变量用引号引起来。
console.log('!{user.name}');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.