搜索框用定时器限制发送请求

html:
<input bindinput="bindKeyInput" value="{{keyword}}" placeholder="搜索学校" bindfocus="focusevent"/>
 
js:
bindKeyInput(e){
var key = e.detail.value,
that = this
if (Interval) {
clearTimeout(Interval)
Interval = null
}
Interval = setTimeout(function () {
that.setData({
keyword: key
})
if (key != '') {
that.search(e)
}
clearTimeout(Interval)
Interval = null
}, 500)
},
 
search(){
let params ={
keyword:this.data.keyword,
}
ApiRequest.getSchool(params).then(res=>{
this.setData({
schoolList:res
})
})
},
posted @ 2020-08-17 17:18  文磊啊~  阅读(137)  评论(0编辑  收藏  举报