Open carcinocron opened 7 years ago
I would rather use a component for this:
I'm not picky about the component vs directive distinction. I'll see if I can come up with something.
Why not using a mixin that adds a now
computed property that updates each second?
Something like:
import Vue from 'vue';
import moment from 'moment';
const component = new Vue({
data: {
now: moment(),
},
created() {
setInterval(() => {
this.now = moment();
}, 1000);
},
});
export default {
computed: {
now() {
return component.now;
},
},
};
In fact, I just created a mixin... https://github.com/skyrpex/now
I'm not happy with that solution, I'll attempt to send a PR if I get something I'm happy with.
I have a Mixin that offers countdowns, intervals, task and the requested feature https://github.com/reinerBa/Vue-Interval as you can see in the demo
I made an issue in this repo, but the author might consider it outside the scope of the library: https://github.com/brockpetrie/vue-moment/issues/24 I'm not requesting "technically how to do it", I'm requesting a clean interface for it.
It would be awesome if we had something for this, except at the moment of inflection (when
moment().isBefore(otherTime)
's status changes fromtrue
tofalse
) Vue is able to detect it as a change and react accordingly.Here is a similar discussion, but did not provide a clean API for accomplishing this. https://github.com/vuejs/Discussion/issues/214
Another possible implementation:
where
v-reset-now-at="otherTime"
might translate to: