export default function debounce(fn, wait) { var timeout; return function() { var ctx = this, args = arguments; clearTimeout(timeout); timeout = setTimeout(function() { fn.apply(ctx, args); }, wait); }; }
引用app
onLoad() { this.scroll = debounce(this.scroll.bind(this), 100); }, scroll(e) { this.setData({ scrollTop: e.detail.scrollTop, }); },