当前位置:网站首页>Electric store stores data

Electric store stores data

2022-06-25 05:09:00 Lijianyi

I don't use database scheme to store data , Simply storing a small amount of simple data does not involve the use of databases . The choice here is electron-store As the primary storage tool , This tool is excellent even if it is not the primary storage tool for storing only user startup items .

install electron-store, If you use npm If the installation is unsuccessful, use cnpm install , There's always one for you .

Usage method :

const Store = require('electron-store');
 
const store = new Store();
// If encrypted storage is required   Just use the following 
//const store = new Store({encryptionKey: ' Encrypted value '}); 
 
store.set('unicorn', ' This is what needs to be stored ');
console.log(store.get('unicorn')); //=> ' This is what needs to be stored '
 
// Use dot-notation to access nested properties
store.set('foo.bar', true);
console.log(store.get('foo')); //=> {bar: true}
 
store.delete('unicorn');
console.log(store.get('unicorn'));  //=> undefined

This code is in main > index.js Try bailing , But in vue The file is surprisingly difficult to use , I'm stuck here 2 Time of day , After adding the corresponding code, the screen will be blank , The page shows nothing , Don't complain .

The final solution is : Downgrade !

When the version is reduced to 4.0 In the future, all the above problems will be solved ~

Not sure 4.0 Can the above version , I tested it directly 4.0, Interested students can test other versions .

Storage uses json file , My storage address here is C:\Users\Administrator\AppData\Roaming\ Project name \config.json

原网站

版权声明
本文为[Lijianyi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210525566464.html