GithubHelp home page GithubHelp logo

electron-localstorage's Introduction

electron-localStorage

在eletron主线程也能使用的localStorage

electron主进程中是不能获取到浏览器的window对象的,所以我们不能像在渲染进程中一样使用浏览器为我们提供的localstorage对象。

但是主进程中有可能也需要这样的需求,比如我们在本地存储了当前的环境(dev/beta/prod),主进程需要根据不同的开发环境来load不同的url。

于是手动封装了一个可以在主进程中调用的localstorage。

1.安装

npm install electron-localstorage

2.引用:

const storage = require('electron-localstorage');

3.使用

3.1完美支持所有localStorage的所有api:

存储数据

storage.setItem(`myCat`, `Tom`);

获取数据

let cat = storage.getItem(`myCat`);

移除某个数据

storage.removeItem(`myCat`);

移除所有数据

storage.clear();

3.2 扩展方法

获取当前所有存储的项

storage.getAll();

自定义存储路径

storage.setStoragePath(path.join(__dirname,'test.json'));

获取当前数据存储路径

storage.getStoragePath();

4.示例程序

https://github.com/ConardLi/electron-localstorage-demo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.