vue 定时器常规操作及其停止

export default {
        data() {
            return {
                min: 1,
                max: 10,
                timer:null //定时器名称
            }
        },
        mounted() {
            this.add();
        },
        methods: {
            add() {
               let _this = this;
               _this.timer = setInterval(function(){//定时器开始
                   _this.min++;
                   if(_this.min == _this.max){
                            clearInterval(_this.timer);// 满足条件时 停止计时
                   }
               },1000)
            },
        }
    };

转自:https://www.kancloud.cn/pengyp/js_node_html_css/1291842

posted @ 2020-06-03 09:28  FancyAnnaYL  阅读(2639)  评论(0编辑  收藏  举报