Created
February 25, 2017 19:26
-
-
Save seanbuscay/cbe3a686c9021d32f408b9989e74b666 to your computer and use it in GitHub Desktop.
How to use Vue Moment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="app"> | |
<ul> | |
<li v-for="item in items"> | |
<p>{{ moment(item).format('MMMM Do YYYY, h:mm:ss a') }}</p> | |
<p class="method">{{ date(item) }}</p> | |
<p class="filter">{{ item | moment }}</p> | |
</li> | |
</ul> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Vue({ | |
el: '#app', | |
data: { | |
items: [ // unix timestamps | |
1481889223, | |
1452945223, | |
1450871623, | |
undefined, | |
1450353223, | |
1450270423, | |
] | |
}, | |
methods: { | |
moment: function (date) { | |
return moment(date); | |
}, | |
date: function (date) { | |
return moment(date).format('MMMM Do YYYY, h:mm:ss a'); | |
} | |
}, | |
filters: { | |
moment: function (date) { | |
return moment(date).format('MMMM Do YYYY, h:mm:ss a'); | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment