python-3.x - 从 api 获取值并显示在 reactjs 应用饼图中
问题描述
我从返回值的地方创建了 API,现在我试图获取这些值并使用 reactjs 在饼图中显示,但无法获取。
class Graph extends Component {
ComponentWillMount(){
fetch('http://localhost:3010/analysis')
.then(response{response.json()})
.then(data => console.log(response))
}
render() {
return (
<ReactFC
{...pieConfigs}/>
);
}
}
export default Graph;
这是我的代码。谁能告诉我为了能够在 React 应用程序中显示饼图需要进行哪些更改?
解决方案
问题是您在组件卸载后立即获取 API,尝试
ComponentDidMount(){
fetch('http://localhost:3010/analysis')
.then(response{response.json()})
.then(data => console.log(response))
}
推荐阅读
- c++ - 在 OSX 上编译 C++ 时找不到库
- oracle - oracledb_exporter 二进制文件
- c++ - C++ 使用来自 CRTP 模板模板基类的构造函数
- google-compute-engine - 用于 kms 的 Python 身份验证
- python - 是否可以通过训练小数据子集来验证深度学习模型?
- r - 在 R 的列表中创建序列
- c++11 - 以下 C++ 标记代码的作用是什么?
- javascript - 在打字稿中将对象传递给构造函数?
- r - 如何标准化 Weka 中基于另一个属性具有不同含义的属性?
- java - 删除数字时应用程序崩溃(redmarobot 输入掩码)