封装防抖节流函数
export const throttle = (fn, interval)=> {
let last = 0
return function () {
let context = this
let args = arguments
let now = +new Date()
if (now - last >= interval) {
last = now;
fn.apply(context, args);
}
}
}
export const debounce = (fn, delay) => {
let timer = null
return function () {
let context = this
let args = arguments
if(timer) {
clearTimeout(timer)
}
timer = setTimeout(function () {
fn.apply(context, args)
}, delay)
}
}
引用函数
import { debounce } from '@/utils/index'
export default {
methods:{
getInput: debounce(function(event){
const value = event.detail.value;
if(value != ''){
this.getCustomerList();
}else{
this.dim = false;
}
},1000),
}
}