首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React本地获取本地API

React本地获取本地API
EN

Stack Overflow用户
提问于 2020-01-22 16:16:29
回答 1查看 49关注 0票数 0

我有一个expo react原生应用程序,我想在另一个项目中使用我制作的API中的函数。我在Postman中测试了该url,该url运行良好。但我得到了一个错误:应用程序中的Network error failed

klt_idklt_name来自客户端表。该url指向一个函数,该函数显示客户端表中的所有记录。

这就是我现在所拥有的:

代码语言:javascript
复制
constructor(props){
    super(props);
    this.state ={ isLoading: true}
  }

  componentDidMount(){
    return fetch('http://127.0.0.1:8000/api/v2/klant', )
      .then((response) => response.json())
      .then((responseJson) => {
        console.log(responseJson)
        this.setState({
          isLoading: false,
          dataSource: responseJson.data,
        }, function(){

        });

      })
      .catch((error) =>{
        console.error(error);
      });
  }


  render(){

    if(this.state.isLoading){
      return(
        <View style={{flex: 1, padding: 20}}>
          <ActivityIndicator/>
        </View>
      )
    }

    return(
      <View style={{flex: 1, paddingTop:20}}>
        <FlatList
          data={this.state.dataSource}
          renderItem={({item}) => <Text>{item.klt_id}, {item.klt_name}</Text>}
          keyExtractor={({id}, index) => id}
        />
      </View>
    );
  }
}

提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2020-01-23 21:37:18

你可以尝试一下ngrok:它将允许你有一个“正常的”HTTPS URL,你应该能够在你的世博会应用程序中使用,而不会出现任何问题。他们网站上的例子:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59855281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档