🚀 Perf: [前台]:搜索加入延迟300ms后发送搜索请求
This commit is contained in:
parent
c1e02db0db
commit
89e08c569e
@ -14,10 +14,24 @@ class Search extends React.Component {
|
||||
};
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.clearTimer();
|
||||
}
|
||||
|
||||
contentChange(e) {
|
||||
const content = e.target.value.trim();
|
||||
this.setState({ content });
|
||||
this.search(content);
|
||||
this.clearTimer();
|
||||
this.timer = setTimeout(() => {
|
||||
this.search(content);
|
||||
this.clearTimer();
|
||||
}, 300);
|
||||
}
|
||||
|
||||
clearTimer() {
|
||||
if (this.timer != null) {
|
||||
clearTimeout(this.timer);
|
||||
}
|
||||
}
|
||||
|
||||
search(content) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user