[英]File download failed in ReactJS
I am trying to download file from src
folder in my react app, but file download is failing我正在尝试从我的 React 应用程序中的
src
文件夹下载文件,但文件下载失败
file import文件导入
import test from "../../test.json";
download下载
const link = document.createElement("a");
link.href = test;
link.setAttribute("download", `test.json`);
document.body.appendChild(link);
link.click();
link.parentNode.removeChild(link);
You can not download files in the src folder.您无法下载 src 文件夹中的文件。 If you need this file and change it in every build, you can use a script and run it before building for copying files from src to the public folder.
如果您需要此文件并在每次构建中更改它,您可以使用脚本并在构建之前运行它以将文件从 src 复制到公共文件夹。 If not, you must copy the file to the public folder.
如果没有,您必须将文件复制到公用文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.