函数节流

函数节流的基本思想是设置一个延时器,在指定时间间隔内运行代码时清除上一次的延时器,并设置另一个延时器,直到函数请求停止并超过时间间隔才会执行。

https://www.cnblogs.com/mopagunda/p/5323080.html

function throttle(method,context){

    clearTimeout(method.tId);

    method.tId=setTimeout(function(){

        method.call(context)

    },300)

}

 

实际代码:实现效果,500ms后才可以点击

that.speakFlag = true;才可以点击

voice-question.vue

if(!this.speakFlag){

return;

}

questionnaire.vue

That.speakFlag = false;

that.speakFlagTimer&&clearTimeout(that.speakFlagTimer);

That.speakFlagTimer = setTimeout(()=>{

That.speakFlag = true;

},500)

 

原文地址:https://www.cnblogs.com/wangge001/p/10131136.html