欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

react+axios實(shí)現(xiàn)github搜索用戶功能(示例代碼)

 更新時(shí)間:2021年09月17日 14:16:47   作者:我要學(xué)web  
這篇文章主要介紹了react+axios實(shí)現(xiàn)搜索github用戶功能,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

在這里插入圖片描述

加載

在這里插入圖片描述

請(qǐng)求成功

在這里插入圖片描述

請(qǐng)求失敗

在這里插入圖片描述

在文件路徑點(diǎn)擊cmd 回車(chē)

在這里插入圖片描述

在這里插入圖片描述
在這里插入圖片描述

首先把服務(wù)器打開(kāi) npm start

在這里插入圖片描述

app.js

import React, { Component } from 'react'
import "./App.css"
import Header from './conompents/Header'
import List from './conompents/List'
export default class App extends Component {
  // 初始化state
  state={
    users:[],
    isloading:false,
    isfirst:true,
    err:''

  }
  update=(updatemessage)=>{
     this.setState(
      updatemessage
     )
  }
  render() {
    return (
      <div className="container">
        <Header update={this.update} />
        <List  users={this.state}></List>
      </div>
    )
  }
}

Header.jsx

import React, { Component } from 'react'
import axios from"axios"

export default class Header extends Component {
  search=()=>{
     console.log(this.searchbtn.value);
     this.props.update({isfirst:false, isloading:true})
     axios.get(`http://localhost:3000/api1/search/users?q=${this.searchbtn.value}`).then(
      //  成功時(shí)回調(diào)
       response=>{
        
         console.log("發(fā)送請(qǐng)求成功",response.data.items);
         this.props.update({users: response.data.items,isloading:false})
       },
      // 失敗時(shí)回調(diào)
      error=>{
        this.props.update({err:error.message,isloading:false})
          console.log("失敗了",error.message);
      }
     )
  } 

    render() {
        return (
            <section className="jumbotron">
            <h3 className="jumbotron-heading">Search Github Users</h3>
            <div>
              <input type="text" placeholder="enter the name you search" 
               ref={c=>this.searchbtn=c}
              />
              &nbsp;
              <button onClick={this.search}>Search</button>
            </div>
          </section>
        )
    }
}

List.jsx

import React, { Component } from 'react'
import Listitem from './Listem'

export default class List extends Component {
  render() {
    return (
      <div className="row">
        {
          this.props.users.isfirst ? <h2 style={{margin:"50px"}}>Welcome to use, please enter the keyword</h2> :
          this.props.users.isloading ? <h2  style={{margin:"50px"}}>Loading......</h2> :
          this.props.users.err ? <h2  style={{margin:"50px"}}>{this.props.users.err}</h2> :
          this.props.users.users.map((a) => {
                  return (
                    <Listitem key={a.id} users={a} />
                  )
                })
        }
      </div>
    )
  }
}

Listitem

import React, { Component } from 'react'
import "./index.css"
export default class Listitem extends Component {
 
    render() {
        return (
            <div className="card"  >
            <a href={this.props.users.html_url} target="_blank" >
              <img src={this.props.users.avatar_url} style={{ width: '100px' }} />
            </a>
            <p className="card-text">{this.props.users.login}</p>
          </div>
        )
    }
}

到此這篇關(guān)于react+axios實(shí)現(xiàn)搜索github用戶功能的文章就介紹到這了,更多相關(guān)react axios github搜索內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • TypeScript在React項(xiàng)目中的使用實(shí)踐總結(jié)

    TypeScript在React項(xiàng)目中的使用實(shí)踐總結(jié)

    這篇文章主要介紹了TypeScript在React項(xiàng)目中的使用總結(jié),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • React?中的重新渲染類組件及函數(shù)組件

    React?中的重新渲染類組件及函數(shù)組件

    這篇文章主要為大家介紹了React?中的重新渲染類組件及函數(shù)組件使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • 在React中應(yīng)用SOLID原則的方法

    在React中應(yīng)用SOLID原則的方法

    SOLID?是一套原則,它們主要是關(guān)心代碼質(zhì)量和可維護(hù)性的軟件專業(yè)人員的指導(dǎo)方針,本文給大家分享如何在React中應(yīng)用SOLID原則,感興趣的朋友一起看看吧
    2022-07-07
  • React Hooks 實(shí)現(xiàn)和由來(lái)以及解決的問(wèn)題詳解

    React Hooks 實(shí)現(xiàn)和由來(lái)以及解決的問(wèn)題詳解

    這篇文章主要介紹了React Hooks 實(shí)現(xiàn)和由來(lái)以及解決的問(wèn)題詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • 關(guān)于React中的聲明式渲染框架問(wèn)題

    關(guān)于React中的聲明式渲染框架問(wèn)題

    這篇文章主要介紹了React中的聲明式渲染框架,我們先討論了命令式和聲明式這兩種范式的差異,其中命令式更加關(guān)注過(guò)程,而聲明式更加關(guān)注結(jié)果,對(duì)React渲染框架知識(shí)感興趣的朋友跟隨小編一起看看吧
    2022-06-06
  • react實(shí)現(xiàn)組件狀態(tài)緩存的示例代碼

    react實(shí)現(xiàn)組件狀態(tài)緩存的示例代碼

    本文主要介紹了react實(shí)現(xiàn)組件狀態(tài)緩存的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • 詳解一個(gè)基于react+webpack的多頁(yè)面應(yīng)用配置

    詳解一個(gè)基于react+webpack的多頁(yè)面應(yīng)用配置

    這篇文章主要介紹了詳解一個(gè)基于react+webpack的多頁(yè)面應(yīng)用配置,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-01-01
  • React實(shí)現(xiàn)二級(jí)聯(lián)動(dòng)的方法

    React實(shí)現(xiàn)二級(jí)聯(lián)動(dòng)的方法

    這篇文章主要為大家詳細(xì)介紹了React實(shí)現(xiàn)二級(jí)聯(lián)動(dòng)的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • React?中在?map()?中使用條件跳出map的方法

    React?中在?map()?中使用條件跳出map的方法

    這篇文章主要介紹了React?中在?map()?中使用條件跳出map的方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-09-09
  • 詳解React的組件通訊

    詳解React的組件通訊

    這篇文章主要介紹了詳解react組件通訊方式,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-11-11

最新評(píng)論