gpt4 book ai didi

momentjs - Moment.js 与 Vuejs

转载 作者:搜寻专家 更新时间:2023-10-30 22:07:15 24 4
gpt4 key购买 nike

我尝试在 vue-for

中使用如下所示打印日期时间
{{ moment().format('MMMM Do YYYY, h:mm:ss a') }}

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

最佳答案

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

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

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

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

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

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

[demo]

关于momentjs - Moment.js 与 Vuejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34308004/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com