1.首先在cmd中下载:
npm install whatwg-fetch
2.在react中引入
import React, { Component } from 'react'
import 'whatwg-fetch'
3.请求数据
fetch('https://api.github.com/users/chrissycoyier/repos')
.then(response => response.json())
.then(data => console.log('data is', data))
.catch(error => console.log('error is', error));