Last active
June 30, 2019 15:09
-
-
Save pespantelis/cdf42a52e5bb8ee095a08abdb58c8edf to your computer and use it in GitHub Desktop.
Moment directive for Vue.js http://codepen.io/pespantelis/pen/oLLLMP
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
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) | |
} | |
}) |
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
@pespantelis
I have update you solution, It's only one setInterval now