【发布时间】:2018-08-31 16:05:21
【问题描述】:
我正在尝试使用 Express 服务器/PostgreSQL 数据库创建 React Native 应用程序。我的一个组件中有以下获取请求
componentDidMount() {
fetch('/users')
.then(response => response.json())
.then(data => {
this.setState({
users: true
})
})
}
“/users”端点在我的服务器文件中定义为:
app.get('/users', (request, response) => {
Users.all().then(users => {
const templateData = {};
templateData.data = users;
response.json(templateData);
})
});
服务器正在监听 4567 端口
在 package.json 中,我有一个这样的代理设置:
"proxy": "http://localhost:5000/",
我的问题是,当调用 componentDidMount 时,我不断收到“网络请求失败”错误。关于如何让我的服务器与我的组件通信的任何想法?谢谢!
【问题讨论】:
标签: json ajax express react-native network-programming