javascript - 来自 API 的 fetch() 数据和来自 API 的 get() 数据是否相同?

标签 javascript node.js reactjs

我的任务是:使用 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 methodsGET, HEAD, POST, DELETE.

不幸的是,我不知道列出这些行话的页面或存储库

关于javascript - 来自 API 的 fetch() 数据和来自 API 的 get() 数据是否相同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66739321/

相关文章:

javascript - 在 React 中将状态变量添加到另一个状态

node.js - 错误 : All configured authentication methods failed levels: 'client-authentication'

node.js - 打印嵌入字符串中的新行

javascript - 带有服务器渲染的 HMR 会导致校验和无效

javascript - 函数式 ReactJS - 将数据/参数传递给回调

javascript - GET 请求在 React Component 中不起作用

javascript - 如何检测 contenteditable 光标位置变化 Safari + iPad + IOS 7?

javascript - 使用 JQuery 或 Javascript 获取设备 ID

javascript - Express中间件中的高阶函数

javascript - 绘制折线图 - 多条线