我有一个用react native expo创建的前端,我的后端是用spring boot完成的,模型在google云中当我在本地运行spring boot并在浏览器中输入URL (没有部署'localhost URL‘)时,它会在浏览器上显示数据。我如何才能在不部署google云的情况下将这些数据放到我的react原生应用程序中。
componentDidMount() {
fetch('http://192.168.56.1:8080/users/toFrontend?email=meNewTwo@gmail.com')
.then((response) => response.json())
.then((json) => {
this.setState({ data: json});
})
.catch((error) => console.error(error))
.finally(() => {
this.setState({ isLoading: false });
});这是我使用的代码
发布于 2020-04-29 14:51:48
fetch('http://{your IP}:8081/')
.then((response) => response.json())
.then((responseJson) => {
this.setState({ message : responseJson.message.data })
})
.catch((error) => {
console.error(error);
}); 现在我们有了命令提示符,让我们输入ipconfig,按enter,然后在IPv4 Address下面抓取数字。此号码为您的本端IP。
REST API
fetch('http://{your IP}:8081/',{
method: 'GET',// denpends upon your call POST or GET
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
}
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
})
.catch((error) =>{
console.error(error);
});
}这是官方的link
发布于 2020-04-29 18:41:32
谢谢你们,终于修复了代码中缺少返回的问题
fetch('URL')
.then((response) => {
return response.json();
})
.then((responseData => {
console.log(responseData);
this.setState({ data: responseData });
}))URL的本地主机部分是IPv4,本地Ip和变量是data:
https://stackoverflow.com/questions/61495560
复制相似问题