我在思考在 .vue 文件中实现 vue-moment 或 moment.js 时遇到了问题。所以我想在 vue 方法中有一个日期,然后我可以操纵它来找到过去时间和当前时间之间的时间跨度并实时更新它。所有的谷歌搜索都把我指向了 moment.js
我的 main.js 文件用
实现了它import VueMoment from 'vue-moment';
Vue.use(VueMoment);
然后我尝试像这样访问模板中的方法
<p>{{ moment(1481889223).format('MMMM Do YYYY, h:mm:ss a') }}</p>
我是否做错了一些固有的事情。我似乎没有时间输出日期/时间
此外,如果这不是解决方案,是否还有另一种在 .vue 文件中访问日期时间的简单方法?
最佳答案
我认为我们在这里缺少的是 vue-moment
将 moment 作为 filter function 引入。 .
Simply set moment as the filtering function and you're good to go. At least one argument is expected, which the filter assumes to be a format string if the argument doesn't match any of the other filtering methods.
知道这一点后,我们就可以相应地传递日期(只要格式正确):
<span>{{ someDate | moment("dddd, MMMM Do YYYY") }}</span>
更具体到原始帖子:
<p>{{ 1481889223 | moment('MMMM Do YYYY, h:mm:ss a') }}</p>
关于javascript - View | vue-moment.js 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55636197/