From 89e08c569efd5e7518195e43e9e44a9a5923c02b Mon Sep 17 00:00:00 2001 From: fanxb Date: Fri, 26 Jul 2019 10:22:55 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Perf:=20[=E5=89=8D=E5=8F=B0]:?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=8A=A0=E5=85=A5=E5=BB=B6=E8=BF=9F300ms?= =?UTF-8?q?=E5=90=8E=E5=8F=91=E9=80=81=E6=90=9C=E7=B4=A2=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/src/components/Search/index.jsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/front/src/components/Search/index.jsx b/front/src/components/Search/index.jsx index 516d0e9..7655dd3 100644 --- a/front/src/components/Search/index.jsx +++ b/front/src/components/Search/index.jsx @@ -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) {