【发布时间】:2017-08-07 07:58:31
【问题描述】:
我正在尝试获取要捕获的输入值,然后使用该值更新部分 URL,所有这些都通过使用 React、ES6 等进行简单的点击来完成。基本上是一个简单的搜索功能
所以我的组件看起来像这样:
class SearchInput extends Component {
constructor() {
super()
this.state = {
query: ''
}
}
componentDidMount = () => {
const handleSearchURL = window.location('/search/'+this.state.query+'/some-action')
this.setState({
handleSearch: handleSearchURL
})
}
queryChange = (evt) => {
this.setState({query: evt.target.value})
}
render() {
const { handleSearch, placeholder } = this.props
return (
<form>
<input id="site-search" type="search" placeholder={placeholder} value={this.state.query} />
<input type="submit" value="Search" onClick={this.handleSearch} />
</form>
)
}
}
但这只会给我很多错误,而且它似乎不喜欢 window.location。实现这一目标的最佳方法是什么?我正在使用 react-router,所以如果有更好的方法,我也很高兴
【问题讨论】:
标签: javascript reactjs ecmascript-6 react-router