import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, TouchableOpacity } from 'react-native'; var DetailVC = require('./DetailVC'); export default class Home extends Component { static defaultProps = { url_api: 'https://www.baidu.com' } constructor(props){ super(props); this.state = { isRefreshing: false }; } render(){ return( <View style={styles.container}> <TouchableOpacity onPress={()=>{this.pushNextVC()}}> <Text style={styles.welcome}> 首页 </Text> </TouchableOpacity> </View> ); } pushNextVC(){ // 界面跳转 // alert(1) this.props.navigator.push( { component: DetailVC, title: 'aaa', passProps: {bbb: 'bbb'}, // 传值 } ); } // 请求网络数据 componentDidMount(){ this.loadData(); } loadData(){ fetch(this.props.url_api) .then((response)=>{response.json()}) // 数据请求,转成json .then((responseData)=>{ alert(responseData) }) .catch((error)=>{ alert(error) }) } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: { fontSize: 20, textAlign: 'center', margin: 10, } }); module.exports = Home;
fetch请求;navigator界面跳转,传值
最新推荐文章于 2022-11-29 22:27:15 发布