铭记

本文详细介绍了在React Native中使用FlatList组件展示动态数据的方法,并实现了下拉刷新功能。通过fetch API进行前后端数据交互,展示了如何设置请求头、发送POST请求及处理响应数据。


<FlatList
data={this.state.stuList}
renderItem={this._renderItem}
keyExtractor={this._keExtractor}
ItemSeparatorComponent={this_reparator}
ListHeaderComponent={this._header}
onRefresh={this._onRefresh}     //下拉刷新头部事件
refreshing={this.state.refreshing}    


/>
this.state={refreshing:false,
stuList:[]};

_renderItem=({item})=>{

return (<View>{item.Xxxx}</View>);
}

_keyExtractor=(item,index)=>{

return item.id.toString();
}

_separator=()=>{

return <View/>
}

_header=()=>{

return <View/>
}
_onRefresh=()=>{
fetch()....
}
-------------------------------------------

前后端连接
fetch(
" ",
{
method:"post",
mode:'cors',
headers:{
Accept:"application/json",
"Content-Type":"application/json"
},
body:JSON.stringify({username:"DeepL"})
}
).then(response=>respone.json())
.then(myjson=>{
this.setState({
ageEvent:china.name;
})
}).cathc(err=>{

alert(err);
})

 

转载于:https://www.cnblogs.com/Wjjxj/p/10141247.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值