A shout out to Scott who gave me a helping hand to turn a simple sample Vue.js app I wrote yesterday into a Vue.js component:
Vue.component("unix-time", {
template: `<div class="time">{{unixtime}}</div>`,
data() {
return {
unixtime: ""
};
},
methods: {
UpdateTime() {
this.unixtime = Math.round(new Date().getTime() / 1000);
}
},
created() {
setInterval(() => {
this.UpdateTime();
}, 1000);
}
});
For any Vue'ers who want the complete code, you can add this component to any root Vue.js element as long as the Vue instance is instantiated after the component appears in the script, for example, any root level element (like the one below) that appears after the component.
new Vue({
el: '#myunixtime',
})
Then, in the HTML, just do something like this:
<div id="myunixtime">
<unix-time></unix-time>
</div>
Thanks again to Scott for learning Vue.js with me and for the helping hand!
Maybe we will add this simple unixtime
clock to the forums somewhere or use this component to replace the unixtime on the home page.....