简体   繁体   English

如何在帕格的console.log?

[英]How to console.log in pug?

How can I console.log the data coming from the backend in pug? 我怎样才能在掌上电脑中调试来自后端的数据?

For instance, this is my backend in expressjs: 例如,这是我在expressjs中的后端:

    res.render("streams/show", {
        stream: cleanStream
    });

in show.pug, I want to inspect the data from steam: 在show.pug中,我想检查来自steam的数据:

- var species = stream.species;
- var fields = [];
- for (var key in species) fields.push(key)
- console.log(fields)

I can't see anything on my Developer Tool on my Chrome. 我在Chrome上的Developer Tool上看不到任何内容。

Any ideas? 有任何想法吗?

Your current method of accessing the data within the template will log information on the backend in the terminal where Express is running, not the frontend in Chrome Developer Tools. 您当前访问模板中数据的方法将在运行Express的终端中的后端记录信息,而不是Chrome Developer Tools中的前端。

In order to access the external information inside the template, you need to nest it inside a script tag and use JSON.stringify in combination with unescaped Pug string interpolation to render it in the HTML as below. 为了访问模板内部的外部信息,您需要将其嵌套在script标记内,并将JSON.stringify与未转义的Pug字符串插值结合使用,以在HTML中呈现它,如下所示。

script
     | var species = !{JSON.stringify(stream.species)};
     | var fields = [];
     | for (var key in species) fields.push(key)
     | console.log(fields)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM