0
我遇到了一些意外的行为,使用react
和fetch
。它应该是非常简单的。本地JSON文件的反应获取请求返回index.html而不是JSON文件
我的代码如下所示:
import React, { Component } from 'react';
class App extends Component {
componentDidMount() {
fetch('/dict.json')
.then(res => res.json())
.then(json => console.log(json))
}
render() {
return (
<p>Example</p>
);
}
}
和我的文件夹结构看起来像这样
- src
|_app.js
|_dict.json
- index.html
当我检查,便请求index.html
页面,这使得没有任何意义,我的网络。有谁之前经历过这个吗?
好的,没错!所以你不能像这样向本地文件提出请求?我认为这是可能的jQuery的Ajax方法? –
https://www.slothparadise.com/how-to-use-jquery-to-grab-json-files/ - 即时通讯困惑:-S –
您的目标是使其在生产环境或本地主机上工作? – linasmnew