带有 Vuejs 的 Moment.js [英] Moment.js with Vuejs

查看:36
本文介绍了带有 Vuejs 的 Moment.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 vue-for

{{ moment().format('MMMM Do YYYY, h:mm:ss a') }}

但是,它没有出现.它只是一个空白.我如何尝试在 vue 中使用 moment?

but, it does not appear. It's just a blank. How I can try to use moment in vue?

推荐答案

使用您的代码,vue.js 试图从其访问 moment() 方法范围.

With your code, the vue.js is trying to access the moment() method from its scope.

因此你应该使用这样的方法:

Hence you should use a method like this:

methods: {
  moment: function () {
    return moment();
  }
},

如果你想给 moment.js 传递一个日期,我建议使用过滤器:

If you want to pass a date to the moment.js, I suggest to use filters:

filters: {
  moment: function (date) {
    return moment(date).format('MMMM Do YYYY, h:mm:ss a');
  }
}

<span>{{ date | moment }}</span>

[演示]

这篇关于带有 Vuejs 的 Moment.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆