防抖
觸發(fā)高頻事件后 n 秒內(nèi)函數(shù)只會執(zhí)行一次,如果 n 秒內(nèi)高頻事件再次被觸發(fā)扔枫,則重新計算時間
<script>
export default {
data() {
return {
timer: null
};
},
methods: {
click() {
clearTimeout(this.timer);
this.timer = setTimeout(() => {
console.log('鼠標單擊');
}, 200);
}
}
};
</script>
節(jié)流
在單位時間內(nèi), 只會觸發(fā)一次事件,如果事件觸發(fā)后锹安,又重復觸發(fā)了同一事件短荐,則忽略后面觸發(fā)的事件倚舀,直到第一次事件的計時結(jié)束
<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);
}
}
}
};
文章的內(nèi)容/靈感都從下方內(nèi)容中借鑒
【持續(xù)維護/更新 500+前端面試題/筆記】https://github.com/noxussj/Interview-Questions/issues
【大數(shù)據(jù)可視化圖表插件】https://www.npmjs.com/package/ns-echarts
【利用 THREE.JS 實現(xiàn) 3D 城市建模(珠海市)】https://3d.noxussj.top/