reactJS可以写入文件吗? [英] Can reactJS write into file?

查看:42
本文介绍了reactJS可以写入文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我的标题所说,这可能吗?我是前端的初学者,现在正在尝试自学 reactJS.我之前学过一些javascript,我知道用它来读写文件是不可能的.我主要想做的是从输入中获取字符串,然后将其写入文件.

As my title says, is it possible? I am begginer at front-end and trying to teach myself reactJS right now. I learned some javascript before and I know it is impossible to read or write files with it. Mainly what I want to do is to get string from input and lets say write it into file.

推荐答案

问题是,那个文件在哪里?

Well the question is, where does that file live?

节点能够写入文件,因为文件存在于运行节点的服务器上.

Node is able to write to files because the files exist on the server that node is running on.

React 在浏览器中运行,因此没有要写入的文件系统.您可以从文件中读取,因为该文件的内容被捆绑到提供给浏览器的 Javascript 中.

React runs in browser so there is no file system to write to. You can read from a file because the contents of that file get bundled into the Javascript that gets served to the browser.

如果要写入文件,则需要从浏览器/React 向服务器发送 API 请求,并让该服务器写入文件系统.

If you want to write to a file, you would need to send an API request from your browser / React to a server and have that server write to the file system.

此外,正如 Huy Nguyen 所指出的,可以从浏览器写入客户端文件系统,但这对该用户来说是私有的.

Additionally, as pointed out by Huy Nguyen, it's possible to write to the clients file system from the browser but that is going to be private to that user.

这篇关于reactJS可以写入文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆