一、html
<template>
<button @click="getData">獲取數(shù)據(jù)</button>
</template>
二、JS文章來源:http://www.zghlxwxcb.cn/news/detail-695327.html
import { throttle } from "@/utils/common";
export default {
methods:{
getData: throttle(async function(params){
console.log(”獲取接口數(shù)據(jù)“,this,parmas)
})
}
}
三、公共方法 common.js文章來源地址http://www.zghlxwxcb.cn/news/detail-695327.html
// 節(jié)流
export const throttle = function (cb, delay) {
let timer = null;
return function (...arg) {
if (timer) return;
cb.call(this, arg[0]);
timer = setTimeout(() => {
timer = null;
}, delay);
};
};
// 防抖
export const debounce = function (cb, delay) {
let timer = null;
return function (...arg) {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
cb.call(this, arg[0]);
}, delay);
};
};
到了這里,關(guān)于vue 防抖與節(jié)流用法的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!