我正在努力用github页面托管我的react应用程序。(使用create-react-app)
并且它不加载data.json文件。
如何从另一台计算机访问我的react应用程序?
为了我的目的,我想更改这个“本地主机版本”代码。
更改URL部分是否足够,比如http://localhost:3001? (否则设置.env ...或使用API ...)
我制作了一些组件文件,并在下面附加了App.js。
import { useHistory } from "react-router-dom";
import useFetch from "../hooks/useFetch";
export default function CreateDay() {
const days = useFetch("http://localhost:3001/days");
const history = useHistory();
function addDay() {
fetch("http://localhost:3001/days/", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
day: days.length + 1,
}),
})
.then( response => {
if(response.ok) {
alert("생성이 완료 되었습니다");
history.push("/voca_app");
}
});
}
return (
<div>
<h3>현재 일수: {days.length}일</h3>
<button onClick={addDay}>Day 추가</button>
</div>
);
}发布于 2021-09-12 09:02:41
签出api(如果你想体验一下) .You也需要托管你的ngrok。
https://stackoverflow.com/questions/69149789
复制相似问题