react中fetch请求

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));

猜你喜欢

转载自blog.csdn.net/qq_43209114/article/details/84073107