【发布时间】:2019-07-11 08:36:15
【问题描述】:
在我的 react native 项目中,我正在尝试使用 axios 从 GET 请求中获取数据。
我知道我需要将 axios.get 中的“localhost”更改为我机器的 IP,即使这样做后我也没有收到我的 console.log 语句的响应。
axios 代码:
import React, { Component } from 'react';
import { View, Text } from 'react-native';
import axios from 'axios';
import PhotoSection from './photo-section';
//functional is just returning some data - static
//smart component for dynamic class component
export default class PhotoFeed extends Component {
render() {
axios.get('http://192.168.1.208:3000/photos')
.then(response=>console.log(response));
return (
<View>
<Text> hello </Text>
</View>
);
}
}
【问题讨论】:
-
在 .then 语句之后使用
.catch(err=>console.log(err));这样您就可以看到错误是什么。
标签: javascript reactjs get axios expo