reactjs - 从配置文件反应加载变量
问题描述
我现在要使用 React 进行前端开发。
为了确保具有最大的灵活性,我想从特定的 CustomConfigFile 加载一些变量。
如果找不到该文件,则应生成该文件,并且可以在 UI 上加载和编辑该文件。
有人可以告诉我这是否可能并举个例子吗?
解决方案
There are three steps you need to do:
If you want to achieve something like that, you need to store those values either in a database or a file in the server, you can use JSON, XML or whatever format you want.
Your client needs to load this file at runtime, you can use
fetch
for this.Now, for the editing part. You are going to need an endpoint you can call from your client, that is able to update those values in the database or in the file. You can use node.js, PHP, ruby or whatever backend language you are comfortable with.
That's the logic you need to implement, I've done it with React + Laravel + MySQL for this app: https://bleext.com/music people can change title, logo, language, the main menu, templates, and so many other things to customize the system.
推荐阅读
- c++builder - 保存和恢复画布->笔状态
- image-processing - 如何确定我的图像是亮文本还是暗文本?[LabVIEW]
- css - 将所有 div 定位到以下两层
- ios - 使用 Linkedin SDK iOS 登录
- reactjs - 反应原生:无法解析“@ant-design/icons-react-native/fonts/antoutline.ttf”
- c# - 如何在 C# 中显示一定时间的消息
- java - 为什么 Xamarin.Android 不是在自定义代理上构建,而是在 VSTS 默认 Visual Studio 2017 代理和 Visual Studio 中构建?
- git - 如何从一个远程获取并推送到另一个
- mule - Mule HTTP 连接器 - 访问资源需要会话
- python-2.7 - cx_Freeze: 'The system cannot find the file specified' during build [win10] [PyQt4] [python2.7] 错误