我的任务是:使用 GET 方法从 http://api.example.com/ 获取 api 信息.我还被告知只能使用:Javascript/Reactjs
然而,无论我在哪里搜索,我都只能获取数据。这两个是一回事吗?还是我看错了教程?
import React, { Component } from 'react';
class App extends Component {
constructor(props) {
super(props);
this.state = {
items: [],
isLoaded: false,
}
}
componentDidMount() {
fetch('https://jsonplaceholder.typicode.com/users')
.then(res => res.json())
.then(json => {
this.setState({
isLoaded: true,
items: json,
})
});
}
render() {
var { isLoaded, items } = this.state;
if (!isLoaded) {
return <div>Loading...</div>
}
else {
return (
<div className="App">
<ul>
{items.map(item => (
<li key={item.uid}>
Name: {item.name} | Email:{item.email}
</li>
))};
</ul>
</div>
);
}
}
}
export default App;
最佳答案
它们是可以互换的,作为该领域的技术术语,“从 api 获取数据”和“从 api 获取数据”意思相同。
如今,在 javascript 中,我们使用 Fetch API与 api 交互,使用 HTTP request methods像 GET
, HEAD
, POST
, DELETE
.
不幸的是,我不知道列出这些行话的页面或存储库
关于javascript - 来自 API 的 fetch() 数据和来自 API 的 get() 数据是否相同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66739321/