【发布时间】:2018-04-08 04:01:16
【问题描述】:
我正在使用 ReactJS 构建一个项目,并且正在尝试读取我已经准备好的本地 JSON 文件。
我有一个 app.js 文件,如下所示:
import React, {Component} from 'react';
import fetch from 'isomorphic-fetch'
import './App.css';
class App extends Component {
getData() {
return fetch('./examples/test.JSON').then(response => {
return response.json();
});
}
componentDidMount() {
console.log(this.getData());
}
render() {
return (
...
);
}
}
导出默认应用;
getData 函数尝试获取 JSON 文件并返回响应。但是,then() 函数和 json() 函数都无法识别。
是否有我缺少的导入?我以为它们会来自 isomorphic-fetch。
【问题讨论】:
-
“无法识别”是什么意思?你的意思是没有定义?你的错误信息是什么?
标签: reactjs