jillztom/vue-moments-ago

the date-property is not reactive

fieteboerner opened this issue · 1 comments

The diff is updating successfully if the time passes.
The problem is that the component is not updating the human diff if the date-string changes. So the date-property is not reactive.

I think this could be solved by accessing the date property this.date directly in the getSeconds-method instead of passing it as a param out of the interval-Loop.

Proposal:

mounted() {
  const interval = setInterval(() => {
    this.getSeconds();
  }, 1000);
  this.$once('hook:destroyed', () => clearInterval(interval));
},
...

getSeconds() {
  const seconds = moment().diff(moment(this.date), "seconds");
  this.humanReadable = this.getDuration(seconds);
  if (this.humanReadable) {
    this.humanDifference = this.humanReadable.interval;
    this.humanWord = this.humanReadable.humanEpoch;
  }
},

Sounds good, could you open a PR?