小编Jai*_*Jai的帖子

使用POST方法获取带有axios的react-native的API数据

我需要使用axios在react-native app中获取数据.我可以使用简单的GET方法获取数据,如下所示:

class AlbumList extends Component {

  state = { albums: [] };

componentWillMount() {
  //axios.get('https://rallycoding.herokuapp.com/api/music_albums') .then(response => console.log(response));
  axios.get('http://rallycoding.herokuapp.com/api/music_albums')

  .then(response => this.setState({ albums: response.data }));
        }
        renderAlbums() {
          return this.state.albums.map(album =>
          <AlbumDetail key={album.title} album={album} />);
         // return this.state.albums.map(album => <Text>{album.title}</Text>);
        }

render() {
    console.log(this.state);

return (
   <View>
        {this.renderAlbums()}
    </View>    
);
}
}
Run Code Online (Sandbox Code Playgroud)

如何从API获取带有POST方法的数据,我还需要传递头文件和api-username,api-password,apitoken?

我需要像/sf/answers/2895098041/这样的东西,但需要AXIOS.

编辑:

我需要从LINNWORK API 获取数据.如果有人这样做,请指导.他们首先需要授权,然后我可以从那里获取数据.所以authrize然后下一步.

react-native axios

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

axios ×1

react-native ×1