本文主要是介绍vue实现带日期星期数字时钟代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<template ><view ><view>{{date}}</view><view>{{time}}</view></view></template><script>import service from '../../service.js';export default {data:{date:'',timerID:'',time:'',week:['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],item:''},mounted:function(){this.updateTime();this.timerID = setInterval(this.updateTime, 1000);},created:function(){},onLoad:function(option){var d=JSON.parse(option.data);this.item=d;},methods:{updateTime:function(){var cd = new Date();this.time = this.zeroPadding(cd.getHours(), 2) + ':' + this.zeroPadding(cd.getMinutes(), 2) + ':' + this.zeroPadding(cd.getSeconds(), 2);this.date = this.zeroPadding(cd.getFullYear(), 4) + '-' + this.zeroPadding(cd.getMonth()+1, 2) + '-' + this.zeroPadding(cd.getDate(), 2) + ' ' + this.week[cd.getDay()];},zeroPadding:function(num, digit){var zero = '';for(var i = 0; i < digit; i++) {zero += '0';}return (zero + num).slice(-digit);}}}
</script><style></style>
这篇关于vue实现带日期星期数字时钟代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!