Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions dist/vue-moments-ago.js

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions src/components/moments-ago.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
</template>

<script>
import Vue from "vue";
import moment from "moment";
Vue.prototype.moment = moment;

export default {
data() {
Expand Down Expand Up @@ -66,10 +64,13 @@ export default {
}
},

mounted() {
setInterval(() => {
this.getSeconds(this.date);
created() {
this.updateDifference();
const interval = setInterval(() => {
this.updateDifference();
}, 1000);

this.$once('hook:destroyed', () => clearInterval(interval));
},

computed: {
Expand All @@ -95,8 +96,8 @@ export default {
},

methods: {
getSeconds(time) {
let seconds = moment().diff(moment(time), "seconds");
updateDifference() {
let seconds = moment().diff(moment(this.date), "seconds");
this.humanReadable = this.getDuration(seconds);
if (this.humanReadable) {
this.humanDifference = this.humanReadable.interval;
Expand Down