constructor(props) {
super(props);
this.state = {
isLoading: true,
search:'',
};
}
componentDidMount(){
var url = 'url='+this.state.search;
axios.get(url)
.then(response =>this.onResponse(response.data));
}
onResponse(gelen){
this.setState({
isLoading:false,
veri:gelen,
});
console.log(this.state.veri);
}
render() {
if (this.state.isLoading) {
return (
<View style={{flex: 1, paddingTop: 20}}>
<ActivityIndicator />
</View>
);
}
return(
<View style={styles.container}>
<TextInput
style={{height: 40, borderColor: 'gray', borderWidth: 1}}
onChangeText = {(search) => this.setState({search})}
placeholder="Welcome">
</TextInput>
</View>
);
}
React Native Search是更改但url不会更改如何更改或更新网址? 我想创建一个搜索页面,我尝试过类似的东西,但是我无法添加数据在数据输入后的数据条目。
答案 0 :(得分:1)
您需要做的就是触发设置搜索状态并激活axios
你可以这样做:
<TextInput
style={{height: 40, borderColor: 'gray', borderWidth: 1}}
onChangeText = {(search) => this.searchData(search)}
placeholder="Welcome">
</TextInput>
searchData(search) {
this.setState({search});
var url = 'url='+search;
axios.get(url).then(response => this.onResponse(response.data));
}