Skip to content

Instantly share code, notes, and snippets.

@seanbuscay
Created February 25, 2017 19:26
Show Gist options
  • Save seanbuscay/cbe3a686c9021d32f408b9989e74b666 to your computer and use it in GitHub Desktop.
Save seanbuscay/cbe3a686c9021d32f408b9989e74b666 to your computer and use it in GitHub Desktop.
How to use Vue Moment
<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>
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