簡體   English   中英

沒有從 api 獲取數據到 web 頁面,任何人都可以幫助我解決這個錯誤,我該怎么做才能獲取數據

[英]Not getting data from api into the web page, can anyone help me through this where I am getting an error and what can i do to get data

從“反應”導入反應;

/**

  • 應用程序

  • 簡單的 react js 獲取示例 */ class App extends React.Component {

    構造函數(道具){

     super(props); this.state = { items: [], isLoaded: false }

    }

    /**

    • 組件DidMount

    • 從給定的 url 獲取 json 對象數組並更新 state。 */ componentDidMount() {

      fetch('https://run.mocky.io/v3/8260aa5d-8af8-4cff-999e-6e81b217f0ba').then(res => res.json()).then(json => { this.setState({項目:json, isLoaded: true, }) }).catch((err) => { console.log(err); });

    }

    /**

    • 使成為

    • 渲染 UI */ render() {

      const { isLoaded, items } = this.state;

      if (.isLoaded) 返回加載中..;;

      返回 (

        {items.map(item => ( 名稱: {item.name} ))}
      );

    }

}

導出默認應用程序;

在渲染 function

return (
       {
         items.clients.map(item => (<span key={item.id}> Name : {item.name} 
                </span>)
             )
       }
   )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM