🚀 Perf: [前台]:搜索加入延迟300ms后发送搜索请求

This commit is contained in:
fanxb 2019-07-26 10:22:55 +08:00
parent c1e02db0db
commit 89e08c569e

View File

@ -14,10 +14,24 @@ class Search extends React.Component {
};
}
componentWillUnmount() {
this.clearTimer();
}
contentChange(e) {
const content = e.target.value.trim();
this.setState({ content });
this.clearTimer();
this.timer = setTimeout(() => {
this.search(content);
this.clearTimer();
}, 300);
}
clearTimer() {
if (this.timer != null) {
clearTimeout(this.timer);
}
}
search(content) {