繁体   English   中英

MomentJs:在Meteor中没有定义矩?

[英]MomentJs: moment is not defined in Meteor?

我是新流星。 我没有在包中添加moment.js。 但是我可以看到moment.js包含在我的渲染页面中。 我认为我添加的任何其他软件包中都包含moment.js。 我的问题是我不能使用包含的moment.js。 当我尝试使用moment.js时,Meteor Exception in template helper: ReferenceError: moment is not defined说“ Exception in template helper: ReferenceError: moment is not defined 可能是什么问题?

在此处输入图片说明

Js:

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

一个简单的答案是,您必须将该软件包实际添加到Meteor。 您显示的HTML源代码只是依赖项指示符。 您将必须从命令行手动添加软件包。

命令如下:

>meteor add momentjs:moment

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

上一行表明已安装了momentjs软件包。 所以现在,无论您可能在什么地方编写了一下代码。 它将开始工作。

暂无
暂无

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

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