1、自定义防抖函数
export function debounce(func, delay=600) { let timer return function (...args) { if (timer) { clearTimeout(timer) } timer = setTimeout(() => { func.apply(this, args) }, delay) } }
2、输入框
<input v-model.trim="searchKey" onInput="onSearchInput"/>
3、防抖函数调用
onSearchInput: debounce(function(e){ let self = this; self.searchKey = e.mp.detail.value; ...your code },600)
原文:https://www.cnblogs.com/Nyan-Workflow-FC/p/14751529.html