节流
规定时间内,只触发一次,可以通过设置immediate来决定触发的时机在这个时间的开始,还是结束的时候执行。
使用uview
// 此处用法为在js中调用,需要写this.$u.throttle()
this.$u.throttle(this.toNext, 500)
1
防抖
使用uview 防止触发多次接口建议使用防抖
// 此处用法为在js中调用,需要写this.$u.debounce()
this.$u.debounce(this.toNext, 500)
1
或者用当前点击时间为判断条件
data() {
return {
lasttime:""
};
},
methods:{
upload(){
let d = new Date();
let nowtime = d.getTime();//获取点击时间
if(nowtime - this.lasttime < 2000){ //如果两次点击事件间隔小于2秒,则不触发后面的接口。
return;
};
this.lasttime = nowtime;
}
}