微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我无法从我的手机上的 expo 项目中的 localhost:30001 上运行的 json-server 获取数据

如何解决我无法从我的手机上的 expo 项目中的 localhost:30001 上运行的 json-server 获取数据

**当我使用 lacalhost:3001 时,它可以在网络上正常工作,但即使我将 localhost 更改为我的 IP 地址也无法在 android 设备上获取数据,然后它也会加载一段时间,然后显示网络请求失败我还附上了那个组件的代码我使用了 redux thunk 从我的 json-server 获取数据我使用了 npm json-server screenshot of the page 我想我的 baseUrl 有问题

export const baseUrl = "http://localhost:3001/"; ** -

 import React,{ Component } from 'react'
 import { View,Text,FlatList,ScrollView} from 'react-native';  
 import {Card,ListItem,Avatar} from 'react-native-elements';
 import { Loading } from './LoadingComponent';
 import { connect } from 'react-redux';
 import { baseUrl } from '../shared/baseUrl';


const mapStatetoProps = state => {
    return {
      leaders: state.leaders
    }
  }

function History(){
        return(
            <Card>
                <Card.Title>Our History</Card.Title>
                <Card.Divider />
                <Card.FeaturedSubtitle style={{color:"#2B2928"}}>Started in 2010,Ristorante con Fusion quickly established itself as a culinary icon par excellence in Hong Kong. With its unique brand of world fusion cuisine that can be found Nowhere else,it enjoys patronage from the A-list clientele in Hong Kong.  Featuring four of the best three-star Michelin chefs in the world,you never kNow what will arrive on your plate the next time you visit us.</Card.FeaturedSubtitle>
                <Card.FeaturedSubtitle style={{color:"#2B2928"}}>The restaurant traces its humble beginnings to The Frying Pan,a successful chain started by our CEO,Mr. Peter Pan,that featured for the first time the world's best cuisines in a pan.</Card.FeaturedSubtitle>           
            </Card>
        )
}


 class AboutComponent extends Component {




render() {

    const renderleader = ({item,index}) => {
        return (    
                <ListItem key={index} >
                    <Avatar rounded source={{uri: baseUrl + item.image}} />
                    <ListItem.Content>
                    <ListItem.Title>{item.name}</ListItem.Title>
                    <ListItem.Subtitle>{item.description}</ListItem.Subtitle>
                    </ListItem.Content>                      
                </ListItem>
        );
    };

   
    if (this.props.leaders.isLoading) {
        return(
            <ScrollView>
                <History />
                <Card
                    title='Corporate leadership'>
                    <Loading />
                </Card>
            </ScrollView>
        );
    }
    else if (this.props.leaders.errMess) {
        return(
            <ScrollView>
                <History />
                <Card
                    title='Corporate leadership'>
                    <Text>{this.props.leaders.errMess}</Text>
                </Card>
            </ScrollView>
        );
    }
    else{
        return (
            <ScrollView>
                <History/>
                <Card>
                    <Card.Title>Corporate leadership</Card.Title>
                    <Card.Divider />
                    <FlatList 
                        data={this.props.leaders.leaders}
                        renderItem={renderleader}
                        keyExtractor={item => item.id.toString()}  
                    />                                  
                </Card>               
            </ScrollView>           
        )
    }

}
}
export default connect(mapStatetoProps)(AboutComponent);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?