我是 Web 开发的新手,不知道如何访问我的 API 的属性。我使用的 API 提供了足球队的信息。给出 API 的架构和链接: https ://rapidapi.com/api-sports/api/api-football?endpoint=apiendpoint_bc5e37ef-299f-4656-98a3-ed0d9fa5b1d2
给定的是我的 React 应用程序的 App.js 代码。
import React from "react";
class App extends React.Component {
constructor() {
super();
this.state = {
teamObj:{}
};
}
componentDidMount() {
fetch("https://api-football-v1.p.rapidapi.com/v2/teams/team/33",
{"method": "GET","headers":
{"x-rapidapi-host": "api-football-v1.p.rapidapi.com",
"x-rapidapi-key": "a35b8572b7mshe694b9e8ac66df4p158c4bjsn4518b48e8965"}
}
)
.then(response => response.json())
.then(data => this.setState({teamObj : data}))
}
render() {
return (
<div>
<h1>My fav team is: {this.state.teamObj.name}</h1>
</div>
);
}
}
export default App;
芜湖不芜
阿晨1998
Helenr
相关分类