【发布时间】:2019-08-02 16:49:09
【问题描述】:
我创建了一个延迟调用 func getTodo 的去抖动函数。它向输入写入字母,但没有任何反应。在网络选项卡中,也是零请求。没有去抖动,搜索工作。
import _, {debounce} from 'lodash';
class App extends Component {
constructor (props) {
super(props);
this.state = {
todos: [],
}
}
search = (query) => {
debounce(() => this.getTodo(query), 1000)
}
getTodo = (query) => {
axios({
url: `/api/v1/todos/{query}`,
method: "GET"
})
.then(res => {
this.setState({
todos: res.data
});
})
.catch(error => {
console.log(error);
})
render () {
return (
<input onChange={this.search} />
)
}
}
【问题讨论】:
标签: javascript reactjs lodash