javascript - fetch 无法正常工作且 console.log 未显示
问题描述
我目前正试图弄清楚为什么我的 .json 文件无法获取。即使我在 fetch 中输入随机字母,它也不会给我任何错误。目前使用 my-react-app。
constructor(props) {
super(props);
this.state = {
productData: [],
}
}
ComponentDidMount() {
this.fetchData();
}
fetchData() {
fetch('./ProductInformation.json')
.then(Response => Response.json())
.then(parsedJSON => console.log(parsedJSON.results))
.catch(error => console.log('parsing failed', error))
}
解决方案
推荐阅读
- python - Plotly:如何在箱线图中更改晶须的长度(最小/最大)?
- arrays - 如何在遵循相同顺序的同时更改数组的开始和结束项?
- mysql - 查找平均工资最高的部门名称
- java - 单选按钮未显示
- docker - 使用 Jenkins 在 Docker 中运行 Gradle 构建时无法 cd 到目录
- python - TypeError:'int'对象不可迭代如何解析python dict
- python - 具有多个输入参数和多个输出参数的神经网络
- mysql - Docker:多个mysql容器
- pdf - PDF 文件元数据的批处理编辑器
- logging - 如何将日志聚合到 splunk 中的持久表?