react jquery方式获取api数据接口

2021-02-09 04:25

阅读:522

标签:jquer   amount   err   com   mock   turn   body   ror   his   

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 
{ error.responseText }
; } else if (!isLoaded) { return
loading...
} else { return (

Records

{records.map((record) => )}
Date Title Amount
); } } } export default Records;

 

react jquery方式获取api数据接口

标签:jquer   amount   err   com   mock   turn   body   ror   his   

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


评论


亲,登录后才可以留言!