简体   繁体   English

如何使用 php 访问位于 ReactJS 中 src 文件夹中的 json 文件

[英]How to access using php a json file located in the src folder in ReactJS

How to access using php a json file located in the src folder in ReactJS如何使用 php 访问位于 ReactJS 中 src 文件夹中的 json 文件

my data.json file in my Project我的项目中的 data.json 文件

After building I can't access to the data.json file构建后我无法访问 data.json 文件

The files look like this build folder这些文件看起来像这个构建文件夹

Generally speaking, you don't.一般来说,你不需要。 The src folder contains the source code for the React app. src 文件夹包含 React 应用程序的源代码。 It isn't something that should be directly used in production.它不应该直接用于生产。

If you are using Webpack to build your production version then, as per this answer you can use the CopyWebpackPlugin plugin to copy the JSON file to your build directory and deploy it with the rest of the application.如果您使用 Webpack 构建您的生产版本,那么根据这个答案,您可以使用CopyWebpackPlugin 插件将 JSON 文件复制到您的构建目录,并使用应用程序的 rest 部署它。

That should give you a predictable file path (if the PHP is on the same system as the server for the React frontend) or URL (otherwise) that you can request with file_get_contents and then parse with json_decode .这应该给你一个可预测的文件路径(如果 PHP 与 React 前端的服务器在同一个系统上)或 URL(否则)你可以用file_get_contents请求然后用json_decode解析。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在位于 SRC 文件夹中的 index.html 文件中注册 service-worker - ReactJS - Register a service-worker in index.html file that's located in SRC folder - ReactJS 如何使用Javascript读取iPhone PhoneGap中项目文件夹中的json文件 - How to read json file located in project folder in iPhone PhoneGap using Javascript 当打字稿文件位于“ ./src”中时,如何构建输出文件夹 - How to build to output folder when the typescript files are located in './src' 如何使用 JS 访问 Vue src 文件夹中的图像 - How to access an image in Vue src folder using JS 如何从PHP中的其他src文件夹加载文件 - How to load a file from a different src folder in php 使用 ReactJS 映射的 json 文件的 img 标签中 src 属性内的正确语法是什么? - What is the correct syntax inside the src property in a img tag for a mapped json file using ReactJS? 如何在 ReactJs 中显示存在于 src 文件夹之外的卡片组件的图像? - How to show the images of card components that exist outside the src folder in ReactJs? 将位于本地的文件夹的完整路径插入json文件 - insert full path of folder which located locally to json file 如何在Javascript代码中访问位于外部PHP文件中的PHP变量? - How to access PHP variables located in external PHP file within Javascript code? 如何使用来自expressjs的reactjs访问json? - How do I access json using reactjs from expressjs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM