例如,我将user
变量传递给此pug文件,并且我想在dom加载后运行一些js代码。
script.
document.addEventListener("DOMContentLoaded", function(event) {
console.log(#{user.name});//log the user's name
});
有可能这样做吗?
首先,您尝试在字符串#{user.name}
外部使用字符串插值。使用!{user.name}
而不是为转义代码插。如果您需要将其包含在字符串中,则还需要将变量用引号引起来。
console.log('!{user.name}');
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句