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>

 

    原文作者:逍遥596607010
    原文地址: https://blog.csdn.net/u013373006/article/details/82464004
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞