Skip to content

Instantly share code, notes, and snippets.

@pespantelis
Last active June 30, 2019 15:09
Show Gist options
  • Save pespantelis/cdf42a52e5bb8ee095a08abdb58c8edf to your computer and use it in GitHub Desktop.
Save pespantelis/cdf42a52e5bb8ee095a08abdb58c8edf to your computer and use it in GitHub Desktop.
Moment directive for Vue.js http://codepen.io/pespantelis/pen/oLLLMP
import Vue from 'vue'
import Moment from 'moment'
Vue.directive('moment-ago', {
update (timestamp) {
this.el.innerHTML = Moment(timestamp).fromNow()
this.interval = setInterval(() => {
this.el.innerHTML = Moment(timestamp).fromNow()
}, 1000)
},
unbind () {
clearInterval(this.interval)
}
})
@bluedarker
Copy link

But still have problem, if use vue-router and setting keep-alive mode, inactive component still keep update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment