小程序中延时获取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
    })

    },

 

posted @ 2020-07-07 11:04  大尹  阅读(431)  评论(0编辑  收藏  举报