一. vue函数防抖
- src下的tools写一个防抖封装函数debounce.js
// 函数防抖
export function debounce(fn, delay){
let timer = null
return function(){
let content = this;
let args = arguments;
if(timer){
clearTimeout(timer)
}
timer = setTimeout(()=>{
fn.apply(content,args)
}, delay)
}
}
- //在需要用到的页面引入
import {debounce} from '@/tools/util.js';
- 需要用到防抖的函数
//输入框值改变
telChange : debounce(val=>{
console.log(val,'111111111111')
},1000),