一、请求数据
1-1 原生
componentDidMount() {
// ctrl+shift+j
var url = "http://192.168.14.15:5000/dj/program?rid=336355127"
fetch(url).then(res => res.json()).then(resJson => {
console.log(resJson.programs)
this.setState({
movies: resJson.programs
})
})
}
1-2 async await
//支持async await
async componentDidMount() {
// ctrl+shift+j
var url = "http://192.168.14.15:5000/dj/program?rid=336355127"
var data = await fetch(url);
var resJson = await data.json();
console.log(resJson)
}
二、渲染数据
2-1 渲染
import { StyleSheet, Text, View,FlatList ,Image} from 'react-native'; //导入组件
export default class SectionListBasics extends Component {
state={
playlists:[]
}
render() {
return (
<View style={styles.container}>
<FlatList
data={this.state.playlists}
renderItem={({item})=><View>
<Text>{item.name}</Text>
<Image style={{width:100,height:100}}
source={{uri:item.coverImgUrl}}
/>
</View>}>
</FlatList>
</View>
);
}
2-2 调试
android studio
1.ctrl+m:打开调试
2.点击Debug
3.ctrl+shift+j //查看页面输入