首页 > 其他 > 详细

Vue 定时执行函数

时间:2019-09-10 01:55:49      阅读:479      评论:0      收藏:0      [点我收藏+]
    <script>
        new Vue({
            el: ‘#app‘,
            data() {
                return {
                    clock: ‘‘,
                }
            },
            mounted() {
                this.$nextTick(() => {
                    setInterval(this.CurentTime, 1000);
                })
            },
            methods: {
                CurentTime() {
                    var getTime = new Date();
                    var year = getTime.getFullYear(); //
                    var month = getTime.getMonth() + 1; //
                    var day = getTime.getDate(); //
                    var hh = getTime.getHours(); //
                    var mm = getTime.getMinutes(); //
                    var ss = getTime.getSeconds(); //
                    var clock = year + "-";
                    if (month < 10)
                        clock += "0";
                    clock += month + "-";

                    if (day < 10)
                        clock += "0";

                    clock += day + " ";

                    if (hh < 10)
                        clock += "0";

                    clock += hh + ":";

                    if (mm < 10) clock += ‘0‘;
                    clock += mm + ":";

                    if (ss < 10) clock += ‘0‘;
                    clock += ss;

                    this.clock = clock
                }

            },
        })
    </script>

 

Vue 定时执行函数

原文:https://www.cnblogs.com/lwming/p/11495151.html

(1)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!