美文网首页uni-app
uni-app之定时器

uni-app之定时器

作者: Cute_小肥鸡 | 来源:发表于2020-12-08 19:07 被阅读0次

    setInterval()

    <template>
    </template>
    
    <script>
        export default {
            data() {
                return {
                    ExamTimeText: '' //考试时间
                }
            },
            onLoad(e) {
                /////////////定时器
                var my_self = this;
                var hour, minute, second; //时 分 秒
                hour = minute = second = 0; //初始化
                var millisecond = 0; //毫秒
                this.timer = setInterval(() => {
                    millisecond = millisecond + 50;
                    if (millisecond >= 1000) {
                        millisecond = 0;
                        second = second + 1;
                    }
                    if (second >= 60) {
                        second = 0;
                        minute = minute + 1;
                    }
                    if (minute >= 60) {
                        minute = 0;
                        hour = hour + 1;
                    }
    
                    //时
                    if (hour < 10) {
                        var hour_1 = '0' + hour;
                    } else {
                        var hour_1 = hour;
                    }
                    //分
                    if (minute < 10) {
                        var minute_1 = '0' + minute;
                    } else {
                        var minute_1 = minute;
                    }
                    //秒
                    if (second < 10) {
                        var second_1 = '0' + second;
                    } else {
                        var second_1 = second;
                    }
                    //将时分秒组成文本
                    my_self.ExamTimeText = hour_1 + '时' + minute_1 + '分' + second_1 + '秒';
                }, 50);
            },
            methods: {
            
            }
        }
    </script>
    
    <style>
    </style>
    
    
    效果图

    相关文章

      网友评论

        本文标题:uni-app之定时器

        本文链接:https://www.haomeiwen.com/subject/alyqgktx.html