Created
January 25, 2019 14:59
-
-
Save supern64/b8b29444b58122fbfb01d0d196676ce8 to your computer and use it in GitHub Desktop.
Simple Clock with Vue.js
This file contains hidden or 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
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script> | |
<center> | |
The current time is: | |
<div id="clock"><h1>{{ time }}<h1></div> | |
</center> |
This file contains hidden or 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
Number.prototype.pad = function(size) { | |
var s = String(this); | |
while (s.length < (size || 2)) {s = "0" + s;} | |
return s; | |
} | |
function formatTime(dateObj) { | |
return dateObj.getHours().pad() + ":" + dateObj.getMinutes().pad() + ":" + dateObj.getSeconds().pad() | |
} | |
const vm = new Vue({ | |
el: "#clock", | |
data: { | |
time: formatTime(new Date()) | |
} | |
}) | |
setInterval(() => { | |
vm.time = formatTime(new Date()) | |
}, 500) |
This file contains hidden or 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
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.22/vue.min.js"></script> |
This file contains hidden or 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
body { | |
font-family: "Segoe UI" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment