流星调试并显示警报,日志和消息(Meteor debugging and showing alerts, logs and messages)

编程入门 行业动态 更新时间:2024-10-20 20:33:55
流星调试并显示警报,日志和消息(Meteor debugging and showing alerts, logs and messages)

我是Meteor的新手,我还在努力了解一些事情是如何运作的。 为了更好地理解语言和工作流程,使用警报和打印消息到控制台是一个好主意。 但我坚持一些事情

我想知道这是一种将消息打印到控制台的简单方法。 例如,当我提交表单时,我无法发出警报,我无法看到我打印的浏览器控制台消息。

我怎么能做这种事呢? 也许打印消息到运行服务器的系统控制台? 有关如何使用控制台,显示消息和警报的任何进一步建议?

I am new to Meteor and I'm still trying to understand how a few things work. To have a better understanding of the language and the workflow, using alerts and printing messages to the console is a great idea. But I'm stuck on a few things

I wonder if the is a simple and default way to print messages to the console. For example, when I submit a form I can't make an alert to work and I can't see the the browser's console message I printed.

How can I do this kind of thing? Maybe printing messages to the system console where the server is running? Any further advise on how to use console, showing messages and alerts?

最满意答案

您基本上可以使用console.log()在javascript中将日志打印到控制台,这基本上就是这个函数所代表的含义。

如果你在期待它时没有在chrome控制台中看到任何结果,可能有以下几个原因:

执行代码时未访问console.log() 。 确保它不在错误的条件范围内

例:

if (false) console.log('print me!'); // this desperate log will never see the light of day else console.log('No, print me!'); // this one always will 您的console.log()在服务器端运行,因此它的输出将打印在您的服务器日志上,通常是您在运行流星的一侧的终端窗口

例:

if (Meteor.isServer) console.log('I\'m on the server!'); // this log will print on the server console if (Meteor.isClient) console.log('I\'m on the client!'); // this log will print on the chrome console console.log('I\'m omnipresent'); // this log will print on both 如果您提到undefined弹出错误,则您尝试打印的变量尚未定义。 确保在打印之前设置了变量

例:

> var real_friend = "Bobby"; > console.log(real_friend); "Bobby" > console.log(imaginary_friend); Error: 'imaginary_friend' is undefined.

You would basically use console.log() to print logs to the console in javascript, that is basically what this function stands for.

If you do not see any results in the chrome console while expecting it, it can be for a few reasons:

Your console.log() is not reached when executing your code. Make sure it is not in the wrong conditional scope

Example:

if (false) console.log('print me!'); // this desperate log will never see the light of day else console.log('No, print me!'); // this one always will Your console.log() is ran on server side, therefore its output will be printed on your server logs, usually the terminal window you have on the side running meteor

Example:

if (Meteor.isServer) console.log('I\'m on the server!'); // this log will print on the server console if (Meteor.isClient) console.log('I\'m on the client!'); // this log will print on the chrome console console.log('I\'m omnipresent'); // this log will print on both If you have an error mentionning undefined popping up, the variable you are trying to print has not yet been defined. Make sure your variable is set before printing it

Example:

> var real_friend = "Bobby"; > console.log(real_friend); "Bobby" > console.log(imaginary_friend); Error: 'imaginary_friend' is undefined.

更多推荐

本文发布于:2023-08-04 08:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1413112.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   流星   消息   日志   Meteor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!