
electron-vue 本地文件读取与写入
vue
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
项目地址:https://gitcode.com/gh_mirrors/vu/vue

·
const fs = require("fs");
const path = require("path");
const { ipcRenderer } = require("electron");
data() {
return {
saveData: []
};
},
// 读取本地配置文件
readBtnToFile() {
// 读取本地配置json文件
const File_path = path
.join(path.resolve("./../"), "/cabinetMachineList.json")
.replace(/\\/g, "\/");
const config_res = JSON.parse(fs.readFileSync(File_path, "utf-8"));
fs.readFile(File_path, "utf8", (err, data) => {
if (err) {
this.$message({
message: "文件读取失败!",
type: "error",
offset: 100,
});
} else {
let list = JSON.parse(data);
console.log(data, list);
this.saveData = list;
// this.$message({
// message: "文件读取成功,并已自动同步!",
// type: "success",
// offset: 100,
// });
}
});
},
// 保存文件
saveBtnToFile() {
// 获取本地配置json文件
const File_path = path
.join(path.resolve("./../"), "/cabinetMachineList.json")
.replace(/\\/g, "\/");
fs.writeFile(File_path, JSON.stringify(this.saveData), "utf8", (err) => {
if (err) {
this.$message({
message: "文件写入失败!",
type: "error",
offset: 100,
});
} else {
this.$root.cabinetMachineList = this.saveData;
this.$message({
message: "文件写入成功!",
type: "success",
offset: 100,
});
}
});
},




vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:5 个月前 )
9e887079
[skip ci] 4 个月前
73486cb5
* chore: fix link broken
Signed-off-by: snoppy <michaleli@foxmail.com>
* Update packages/template-compiler/README.md [skip ci]
---------
Signed-off-by: snoppy <michaleli@foxmail.com>
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 7 个月前
更多推荐
所有评论(0)