具体封装公共方法请看:vue封装公共方法
//防抖函数方法 只执行最后一次点击
//使用方法: this.$Debounce('方法','时间')()
let timer
Vue.prototype.$Debounce = function(fn,delay){
var delay = delay || 300;
return () => {
var args = arguments;
var that = this;
clearTimeout(timer)
timer = setTimeout(function(){
fn.apply(that,args)
},delay)
}
};
调用
注意点:别忘了加()
this.$Debounce(()=>{
console.log("我打印了")
},1000)()