利用electron-store持久化用户数据
发布日期:2021-07-01 05:17:38 浏览次数:2 分类:技术文章

本文共 746 字,大约阅读时间需要 2 分钟。

Electron没有内置的方法来持久保存用户首选项和其他数据。使用electron-store模块可以帮助完成上述需求,专注于构建应用程序。数据保存在JSON文件中app.getPath(‘userData’)。

GitHub地址:https://github.com/sindresorhus/electron-store


安装

$ npm install electron-store --save

使用

const Store = require('electron-store');const store = new Store();store.set('unicorn', '?');console.log(store.get('unicorn'));//=> '?'// Use dot-notation to access nested propertiesstore.set('foo.bar', true);console.log(store.get('foo'));//=> {bar: true}store.delete('unicorn');console.log(store.get('unicorn'));//=> undefined

保存位置

The data is saved in a JSON file in $ app.getPath('userData').

console.log(app.getPath('userData'));//=> C:\Users\xxx\AppData\Roaming\electron-quick-start

打开该路径下config.json文件

{
"foo": {
"bar": true }}

转载地址:https://onefine.blog.csdn.net/article/details/100081418 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:网络层之IP编址的历史阶段
下一篇:ipcMain、ipcRenderer——主进程和渲染进程之间的异步通信

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年05月02日 10时23分16秒