文件写入没有生效
来源:8-5 在 App 中集成文件操作

慕的地9371463
2019-11-13
请教老师文件写入为什么没有生效
通过nodejs直接执行fileHelper.js是生效的,在App.js中调用就不生效了,但的确走了promise的resolve
electron中的nodejs版本是12.8.1
electron版本 7.1.1
windows 10
fileHelper.js
const fs = window.require('fs').promises
const path = window.require('path')
const fileHelper = {
readFile: (path) => {
return fs.readFile(path, {encoding: 'utf8'})
},
writeFile: (path, content) => {
console.log(path, content, '---文件操作入参')
return fs.writeFile(path, content, {encoding: 'utf8'})
},
renameFile: (path, newPath) => {
return fs.rename(path, newPath)
},
deleteFile: (path) => {
return fs.unlink(path)
}
}
App.js
import fileHelper from './utils/fileHelper'
const {remote} = window.require('electron')
const {join} = window.require('path')
const savedLocation = remote.app.getPath('documents')
fileHelper.writeFile(join(savedLocation, `${title}.md`), files[id].body)
.then(res => {
// setFiles({...files, [id]: newFile})
console.log('完成', res)
}).catch(err => {
console.log('异常', err)
})
写回答
1回答
-
慕的地9371463
提问者
2019-11-13
已解决
112021-01-25
相似问题