<script>
    export default {
        name:'test',
        data(){
            return {
                time: 60,
                timer:null,
            }
        }, 

        methods: {
            // 60s倒计时
            getLastTime: function(){
                this.timer = setInterval(function () {
                    if(this.time == 0){
                        this.time = 60;
                        clearInterval(this.timer);
                    }else {
                        this.time = this.time - 1;
                    }
                },1000) 
            },
        },
        destroyed(){
            if(this.timer) { //如果定时器在运行则关闭
                clearInterval(this.timer); 
            }
        }
    }
</script>

 

Logo

前往低代码交流专区

更多推荐