【发布时间】:2020-11-17 14:19:17
【问题描述】:
我使用 vue cli 创建了一个新的 Vue 项目。现在,当我在 main.js 中添加文件写入代码时,它给出了错误。
代码:
const fs = require('fs') ;
// Data which will write in a file.
let data = "Learning how to write in a file.";
// Write data in 'Output.txt' .
fs.writeFile('Output.txt', data, (err) => {
// In case of a error throw err.
if (err) throw err;
}) ;
错误: 未捕获的类型错误:fs.writeFile 不是函数 在 eval (main.js?56d7:20) 在 Module../src/main.js (app.js:1217) 在 webpack_require (app.js:854) 在 fn (app.js:151) 在 Object.1 (app.js:1278) 在 webpack_require (app.js:854) 在 checkDeferredModules (app.js:46) 在 app.js:994 在 app.js:997
【问题讨论】:
-
所以您尝试在浏览器中使用文件系统
fs?顺便说一句,女巫是不可能的,只能在 nodejs 中使用 -
我已经写在js文件里了。有什么办法可以用 Javascript 写文件吗?
-
在浏览器中,没有
-
可以提示用户下载文件,更多信息请到this question。
-
非常感谢您的回复。
标签: javascript node.js vue.js fs