MomentJs:Meteor中没有定义时刻?

时间:2022-01-10 18:23:56

I am new in meteor. I doest add moment.js in my package. But I can see moment.js is included in my rendered page. I think moment.js included by any other package which is added by me. My question is I can't use that included moment.js. When I try to use moment.js Meteor says Exception in template helper: ReferenceError: moment is not defined. What might be the problem?

我是流星的新手。我在我的包中添加了moment.js。但我可以看到moment.js包含在我的渲染页面中。我认为moment.js包含在我添加的任何其他包中。我的问题是我不能使用包括moment.js。当我尝试使用moment.js Meteor说模板帮助器中的异常:ReferenceError:moment未定义。可能是什么问题?

MomentJs:Meteor中没有定义时刻?

Js:

Template.Home.helpers({
  fromnow: function(time){
    console.log(time);
    return moment(time).fromNow();
  }
});

1 个解决方案

#1


the simple answer to this is that you have to actually add that package to Meteor. The HTML source that you are showing is just the dependency indicator. You will have to add the package manually from command line.

对此的简单回答是,您必须将该包实际添加到Meteor。您显示的HTML源只是依赖关系指示器。您必须从命令行手动添加包。

command is as follows:

命令如下:

>meteor add momentjs:moment

momentjs:moment: Moment.js (official): parse, validate, manipulate, and display dates - official Meteor packaging

The above line indicates that the momentjs package is installed. So now, wherever you might have written the code for moment. It will start working.

上面的行表示已安装momentjs包。所以,现在,无论你在哪里编写代码的时刻。它将开始工作。

#1


the simple answer to this is that you have to actually add that package to Meteor. The HTML source that you are showing is just the dependency indicator. You will have to add the package manually from command line.

对此的简单回答是,您必须将该包实际添加到Meteor。您显示的HTML源只是依赖关系指示器。您必须从命令行手动添加包。

command is as follows:

命令如下:

>meteor add momentjs:moment

momentjs:moment: Moment.js (official): parse, validate, manipulate, and display dates - official Meteor packaging

The above line indicates that the momentjs package is installed. So now, wherever you might have written the code for moment. It will start working.

上面的行表示已安装momentjs包。所以,现在,无论你在哪里编写代码的时刻。它将开始工作。