react jquery方式获取api数据接口

import React, { Component } from ‘react‘;
import Record from ‘./Record‘;
import { getJSON } from ‘jquery‘;

class Records extends Component {
  constructor() {
    super();

    this.state = {
      error: null,
      isLoaded: false,
      records: []
    };
  }

  componentDidMount() {
    getJSON(‘https://5aa780cb7f6fcb0014ee24aa.mockapi.io/api/v1/records‘).then(
      res => {
        this.setState({
          isLoaded: true,
          records: res
        });
      },
      error => {
        this.setState({
          isLoaded: true,
          error
        })
      }
    )
  }

  render() {
    const { error, isLoaded, records } = this.state;
    if (error) {
      return <div>{ error.responseText }</div>;
    } else if (!isLoaded) {
      return <div>loading...</div>
    } else {
      return (
        <div>
          <h2>Records</h2>
          <table className=‘table table-bordered‘>
            <thead>
              <tr>
                <th>Date</th>
                <th>Title</th>
                <th>Amount</th>
              </tr>
            </thead>
            <tbody>
              {records.map((record) => <Record {...record} key={record.id}/>)}
            </tbody>
          </table>
        </div>
      );
    }

  }
}

export default Records;

原文地址:https://www.cnblogs.com/sunbey/p/8568204.html

时间: 2024-08-01 22:45:45

react jquery方式获取api数据接口的相关文章

jQuery异步获取json数据的2种方式

jQuery异步获取json数据有2种方式,一个是$.getJSON方法,一个是$.ajax方法.本篇体验使用这2种方式异步获取json数据,然后追加到页面. 在根目录下创建data.json文件: { "one" : "Hello", "two" : "World" } ■ 通过$.getJSON方法获取json数据 <script src="Scripts/jquery-2.1.1.min.js"

使用图片跨域方式获取图片数据 使用 jsonp 方式跨域获取数据

使用图片跨域方式获取图片数据 server.get(`/mockImg`, (req, res, next) => { // 使用图片跨域方式获取图片数据 req.headers.origin && res.setHeader(`Access-Control-Allow-Origin`, req.headers.origin) res.setHeader(`content-type`, `image/gif`) res.setHeader(`data`, `image/gif`) v

jquery $.ajax 获取josn数据

<script type="text/javascript" src="jquery-1.9.1.js"></script> <script type="text/javascript"> function test() { $.ajax({ type: "get", cache: false, url: "../../ajax/Task.aspx", data: 'id

Jquery 方式获取 iframe Dom元素

Jquery 方式获取 iframe Dom元素 测试页面代码: <html>  <head>   <title>jquery方式,访问iframe页面dom元素</title>   <meta name="Author" content="孙勤波">   <meta http-equiv="Content-Type" content="text/html;charset

基于百度风云榜开发的API数据接口-为APP资讯资讯服务

是基于百度搜索风云榜采集的新闻信息,,该资讯会更好的体现人们关注的人多事件与热词 通过数据采集,同时发布相信的数据开放API接口 1.取得热词信息列表 如:api.yi18.net/top/list 2.取得热词信息详细 如:api.yi18.net/top/show?id=1 更多的API文档 doc.yi18.net/topwendang 数据镜像网站:  top.yi18.net API数据接口的免费开放,希望为更多的APP开发者提供更专业的数据 接口.为APP开发提供更简单的新闻热点板块

利用sendmsg和recvmsg来指定发送接口或者获取接收数据接口

前言 sendmsg和recvmsg函数是一对相对下层的套接字发送.接受函数.通过这对函数,我们可以设置或者取得数据包的一些额外的控制信息,这些信息中比较常用的就是本文要介绍的发送.接受接口信息.通过这对函数,我们可以指定一个数据包发送的时候使用的接口(网卡)或者获得一个接受到数据包的来源接口. sendmsg函数使用 sendmsg(fd, &mhdr, 0)函数中最重要的就是msghdr结构体.其定义如下: struct msghdr { void *msg_name; #发送地址 sock

在线图书API接口-图书馆API数据接口

生活图书馆 http://book.yi18.net 专门收集健康.生活.医药.医学等相关的健康生在线图书馆! 同时网站也开发的相应的API接口,提供给APP爱好者免费调用与开发. API文档地址:http://doc.yi18.net/bookapidoc . 更多的API更新请关注:http://open.yi18.net/apidoc    个人开放平台,,求支持 数据接口简介(详情API地址http://doc.yi18.net/bookapidoc ): 1.取得图书分类 http:/

JQuery UI获取JSON数据

最近在学习用JQuery UI开发一个界面,这是javascript的一个框架,功能强大,界面漂亮. 首先要下载JQuery UI的包,引入里面的文件: <link href="jquery-ui.css" rel="stylesheet"> <script src="external/jquery/jquery.js"></script> <script src="jquery-ui.js&q

Java程序API数据接口

API:应用程序接口(API:Application Program Interface) 一.使用数据接口的作用 1.封装逻辑 数据接口从数据库查询出数据,并组织成json格式,这个逻辑如果在每个终端都写一遍,那样将编写大量重复代码 2.便于分布部署 可以部署多份API便于多个终端使用 3.提高安全性 可以避免从APP端直接访问数据库 图1  API是连接应用集群与数据库的桥梁 API 同时也是一种中间件,为各种不同平台提供数据共享.根据单个或分布式平台上不同软件应用程序间的数据共享性能,可以