# vuex-local-state

> vuex plugin

Latest version **1.1.2** (published 2017-09-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install vuex-local-state
pnpm add vuex-local-state
yarn add vuex-local-state
bun add vuex-local-state
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2017-09-29 |
| First published | 2017-07-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | imconfig |
| Maintainers | imconfig |
| Keywords | vuex-local-state, vuex, localStorage |

## Links

- npm: https://www.npmjs.com/package/vuex-local-state
- Repository: https://github.com/biluochun/vuex-localState
- Homepage: https://github.com/biluochun/vuex-localState#readme
- Issues: https://github.com/biluochun/vuex-localState/issues
- npm.io page: https://npm.io/package/vuex-local-state

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2017-09-29
- 1.1.1 — 2017-07-28
- 1.1.0 — 2017-07-28
- 1.0.3 — 2017-07-28
- 1.0.2 — 2017-07-28
- 1.0.1 — 2017-07-28
- 1.0.0 — 2017-07-28

## README

# vuex-local-state
inject localStorage to vuex

## Installation
```bash
$ npm install vuex-local-state --save
```

## API
    new VuexLocalState(storeOptions, [conf]);
    conf default: {
        namespace: '_vued',
        storage: window.localStorage,
        key: 'localState',
    }


## [Examples](https://biluochun.github.io/vuex-localState/test/index.html)

## Usage
```js

import * as Vue from 'vue';
import * as Vuex from 'vuex';
import * as VuexLocalState from 'vuex-local-state';
import subModule from './subModule.js';

const storeOptions = {
    // https://vuex.vuejs.org/zh-cn/state.html
    state: {},

    // vuex-local-state inject
    // 1、 data in vuex and localStorage,
    // 2、 can be a Function: function (count) { return (count || 0) + 1; }
    // 3、 use: store.state.xxx
    // 4、 [Not] use: store.localState.xxx
    localState: {
        count: oldValue => (oldValue || 0) + 1,
    },

    actions: {},
    getters: {},
    mutations: {},
    modules: { subModule },
};

new VuexLocalState(storeOptions);

Vue.use(Vuex);
export new Vuex.Store(storeOptions);
```

```js
// subModule.js
// vuex module
export default {
    // https://vuex.vuejs.org/zh-cn/state.html
    state: {},

    // vuex-local-state inject
    // 1、 data in vuex and localStorage,
    // 2、 can be a Function: function (count) { return (count || 0) + 1; }
    // 3、 use: store.state.xxx
    // 4、 [Not] use: store.localState.xxx
    localState: {
        aaaaa: 1,
        bbbbb: null,
        ccccc: oldValue => (oldValue || 0) + 1,
        ddddd: (oldValue = {}) => {
            if (Date.now() - (oldValue.saveTime || 0) < 60 * 1000) return oldValue;
            return {};
        },
    },

    getters: {},
    actions: {},
    mutations: {},
};

```

---
_Source: https://npm.io/package/vuex-local-state · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
