【发布时间】:2020-11-02 02:32:19
【问题描述】:
我正在尝试获取本地文件“file.html”并将其设置为字符串状态。该程序无法在 src 文件夹中找到我的文件,而是在公共文件夹中。如何在 src 中做到这一点。
const [html, setHTML] = useState("");
async function getProjectCode() {
const file = "file.html"
await fetch(file)
.then((response) => response.text())
.then((data) => {
setHTML(data);
});
}
【问题讨论】:
-
在codesandbox中添加示例代码进行调试