componentDidMount() {
this.getFirst();
}
//上拉加载
getFirst = () => {
let api =
"https://cnodejs.org/api/v1/topics?page=" +
this.state.page +
"&tab=job&limit=20";
fetch(api)
.then(arr => arr.json())
.then(aee => {
this.setState({
data: aee.data
});
});
};
//下拉加载
getNext = () => {
this.setState({
page: this.state.page + 1
});
let api =
"https://cnodejs.org/api/v1/topics?page=" +
this.state.page +
"&tab=job&limit=20";
fetch(api)
.then(arr => arr.json())
.then(aee => {
this.setState({
data: [...this.state.data, ...aee.data]
});
});
};
//渲染Flastlist
render() {
return (
<FlatList
data={this.state.data}
renderItem={({ item }) => {
return (
<TouchableOpacity
onPress={() => {
this.props.navigation.navigate("Detils", { name: item });
}}
>
<View>
<Text style={{ fontSize: 20 }}>{item.title}</Text>
</View>
</TouchableOpacity>
);
}}
//进度条
refreshing={this.state.refreshed}
onRefresh={this.getFirst}
onEndReached={this.getNext}
onEndReachedThreshold={0.0001}
/>
);
}
网友评论