搜索框的延时加载逻辑

      发布在:前端技术      评论:0 条评论

原理:

  1. 输入时调用getSearch方法

  2. 执行clearTimeout,关闭定时器

  3. 再开启定时器

  4. 如果有继续输入的操作,会执行1,2,3步。如果没有,直接执行想要的操作

// 获取搜索框内容,延时加载
getSearch(e) {
let value = e.detail.value
this.setData({
searchValue: value
})
let that = this
clearTimeout(this.data.timer)
this.data.timer = setTimeout(function () {
that.init();
}, 1000);
},

来源:https://blog.csdn.net/yugoup/article/details/107665144

相关文章
热门推荐