当前位置:首页 > Windows程序 > 正文

records: []}; }componentDidMount() {getJSON( ‘https://5aa780

2024-03-31 Windows程序

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;

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/34222.html

Jm-杰米博客Jamie
草根站长的技术交流乐园!IT不会不要紧快来好好学习吧!
  • 20786文章总数
  • 7494588访问次数
  • 建站天数
  • 友情链接