官方文档:
https://reactnative.cn/docs/network/#使用-fetch
例子,复制即可使用
HttpGet.js
/**
* fetch 的get请求
*https://reactnative.cn/docs/network/#使用-fetch
*/
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Button} from 'react-native';
export default class HttpGet extends Component {
/**
* get请求数据
* @returns {Promise<void>}
*/
httpRequest = async () => {
let url = `https://douban.uieee.com/v2/movie/coming_soon`;
// 请求数据
let rawData = await fetch(url,{
method: 'GET',
});
//拿到的数据转成json字符串
let dataStr = await rawData.text();
// 转化成json
let jsonData = JSON.parse(dataStr);
//打印结果
console.warn(jsonData);
}
render() {
return (