Skip to content

Commit ff346b0

Browse files
committed
Improve display time with mounted
1 parent 1ed7a9f commit ff346b0

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

public/app.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7431,20 +7431,17 @@ var Clock = {render: function(){with(this){return _h('div',{staticClass:"clock"}
74317431
}
74327432
},
74337433
mounted: function mounted () {
7434-
this.updateDateTime()
7434+
setInterval(this.updateDateTime, 1000)
74357435
},
74367436
methods: {
74377437
updateDateTime: function updateDateTime () {
7438-
var self = this
74397438
var now = new Date()
74407439

7441-
self.hours = now.getHours()
7442-
self.minutes = getZeroPad(now.getMinutes())
7443-
self.seconds = getZeroPad(now.getSeconds())
7444-
self.hourtime = getHourTime(self.hours)
7445-
self.hours = self.hours % 12 || 12
7446-
7447-
setTimeout(self.updateDateTime, 1000)
7440+
this.hours = now.getHours()
7441+
this.minutes = getZeroPad(now.getMinutes())
7442+
this.seconds = getZeroPad(now.getSeconds())
7443+
this.hourtime = getHourTime(this.hours)
7444+
this.hours = this.hours % 12 || 12
74487445
}
74497446
}
74507447
}

src/components/Clock.vue

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,17 @@ export default {
2222
}
2323
},
2424
mounted () {
25-
this.updateDateTime()
25+
setInterval(this.updateDateTime, 1000)
2626
},
2727
methods: {
2828
updateDateTime () {
29-
let self = this
3029
let now = new Date()
3130
32-
self.hours = now.getHours()
33-
self.minutes = getZeroPad(now.getMinutes())
34-
self.seconds = getZeroPad(now.getSeconds())
35-
self.hourtime = getHourTime(self.hours)
36-
self.hours = self.hours % 12 || 12
37-
38-
setTimeout(self.updateDateTime, 1000)
31+
this.hours = now.getHours()
32+
this.minutes = getZeroPad(now.getMinutes())
33+
this.seconds = getZeroPad(now.getSeconds())
34+
this.hourtime = getHourTime(this.hours)
35+
this.hours = this.hours % 12 || 12
3936
}
4037
}
4138
}

0 commit comments

Comments
 (0)