的keys。

const Store = require('electron-store');

class PluginStore {
  constructor(pluginId) {
    this.store = new Store({ name: pluginId });
  }

  set(key, value) {
    this.store.set(key, value);
  }

  get(key) {
    return this.store.get(key);
  }

  delete(key) {
    this.store.delete(key);
  }

  getAllKeys() {
    return this.store.store;
  }
}

使用示例:

const pluginId = 'my-plugin';
const myPluginStore = new PluginStore(pluginId);

myPluginStore.set('name', 'My Plugin');
myPluginStore.set('version', '1.0.0');

console.log(myPluginStore.get('name')); // My Plugin
console.log(myPluginStore.get('version')); // 1.0.0

myPluginStore.delete('version');

console.log(myPluginStore.get('version')); // undefined

console.log(myPluginStore.getAllKeys()); // { name: 'My Plugin' }
``
使用electron-store写一个通用的存储他是用来存储每个插件的数据也就是根据插件id隔离的可以对插件的数据增删改查同时可以列出所有store

原文地址: http://www.cveoy.top/t/topic/eGHu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录