小程序中延时获取input的值

changeSearchVal(e){
    let keyWord = e.detail.value ? e.detail.value : null
    let that = this;
    if(timer){
      clearTimeout(timer)
    }
    timer = setTimeout(()=>{
      if(keyWord==null){
        //这里表示  如果搜索框中没有数据的话,做的一些处理
      }else{
        //这里是搜索框中有值的情况,可以直接请求搜索接口即可
      }
    },1000)
    that.setData({
      searchVal:keyWord,
      timer:null
    })

    },
原文地址:https://www.cnblogs.com/dayin1/p/13259591.html