首页 > 其他 > 详细

vue: 输入防抖实现

时间:2021-05-10 19:56:09      阅读:15      评论:0      收藏:0      [点我收藏+]

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)

 

vue: 输入防抖实现

原文:https://www.cnblogs.com/Nyan-Workflow-FC/p/14751529.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!