防抖
触发高频事件后 n 秒内函数只会执行一次,如果 n 秒内高频事件再次被触发,则重新计算时间
<script>
export default {
data() {
return {
timer: null
};
},
methods: {
click() {
clearTimeout(this.timer);
this.timer = setTimeout(() => {
console.log('鼠标单击');
}, 200);
}
}
};
</script>
节流
在单位时间内, 只会触发一次事件,如果事件触发后,又重复触发了同一事件,则忽略后面触发的事件,直到第一次事件的计时结束
<script>
export default {
data() {
return {
isFinshed: true
};
},
methods: {
click() {
if (this.isFinshed === true) {
this.isFinshed = false;
this.timer = setTimeout(() => {
console.log('鼠标单击');
this.isFinshed = true;
}, 200);
}
}
}
};
點(diǎn)擊查看更多內(nèi)容
為 TA 點(diǎn)贊
評論
評論
共同學(xué)習(xí),寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦