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();
}
},
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>
[demo]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…