Moment.js与Vuejs [英] Moment.js with Vuejs
本文介绍了Moment.js与Vuejs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用vue-for
{{ moment().format('MMMM Do YYYY, h:mm:ss a') }}
但是,它没有出现.只是一片空白.我该如何尝试在瞬间发挥作用?
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>
这篇关于Moment.js与Vuejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文