首页 > 解决方案 > 节点 vue.js/electron 无法使用 browserify-fs 保存文件

问题描述

我正在开发一个节点 vue.js/electron 项目。我正在尝试保存文件。

  const fs = require("browserify-fs");
  
  console.log(data);
  const buffer = JSON.stringify(contents);

  fs.open(data, "w", function (err, fd) {
    if (err) {
      throw "could not open file: " + err;
    }

    // write the contents of the buffer, 
    // from position 0 to the end, 
    // to the file descriptor returned in opening our file
    
    fs.write(fd, buffer, 0, buffer.length, null, function (err) {
      if (err) throw "error writing file: " + err;
      fs.close(fd, function () {
        console.log("wrote the file successfully");
      });
    });
  });
  

我认为这应该有效。这是在我的终端中。

  /home/dave/temp.txt
  wrote the file successfully

当我查看我的主目录时,没有“temp.txt”。

标签: node.jsvue.jsfs

解决方案


推荐阅读