javascript - 在 React 中使用 fetch 从 API 获取数据
解决方案
您可以使用 javascript 获取 API
获取示例
fetch(`https://jsonplaceholder.typicode.com/posts?key=${key}&results=${results}`)
.then((res) => { return res.json() })
.then((data) => {
console.log(data)
});
})
}
发布示例
let key = 'key'
let results = 12;
fetch('https://jsonplaceholder.typicode.com/posts', {
method: 'POST',
headers : new Headers(),
body:JSON.stringify({key: key, results: results})//use property short hand here
}).then((res) => res.json())
.then((data) => console.log(data))
.catch((err)=>console.log(err))
推荐阅读
- pytest - 使用 pytest 测试 Django 干净表单方法的正确方法
- python - OpenCV相机捕捉到没有光
- c++ - 是否有任何用于移动设备的 C++ 图形库?
- flutter - Flutter Cupertino 开关
- node.js - 是否有用于 Nest.js 的 Open API 代码生成器的模块
- python - 将股票指标添加到 Pandas DataFrame - ValueError:系列的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或
- python - 如何从 restful api django 获取详细信息?
- javascript - 如何让 javascript 将类添加到 LI 标记
- python - 根据与另一个数据框的匹配在数据框中创建新列
- python - 在 Dataframe 列中查找特定字符串