具体封装公共方法请看:vue封装公共方法
//节流方法 只执行第一次点击
//使用方法: this.$Throttle('方法','时间')()
let flag = true
Vue.prototype.$Throttle = function(f,t){
return () => {
if (flag) {
f();
flag = false;
setTimeout(() => {
flag = true
},t)
}
}
};
调用
注意点:别忘了加()
this.$Throttle(()=>{
console.log("我打印了")
},1000)()