# vue-persist-state

> Provide global $state that is stored in localStorage or Cookie

Latest version **2.0.0** (published 2022-07-18) · MIT license · 19 weekly downloads

## Install

```sh
npm install vue-persist-state
pnpm add vue-persist-state
yarn add vue-persist-state
bun add vue-persist-state
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2022-07-18 |
| First published | 2018-03-20 |
| Weekly downloads | 19 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Gormartsen |
| Maintainers | gormartsen |
| Keywords | vue, vue3, state, localstorage, persistent, reactive |

## Links

- npm: https://www.npmjs.com/package/vue-persist-state
- Repository: https://github.com/Gormartsen/vue-persist-state
- Homepage: https://github.com/Gormartsen/vue-persist-state#readme
- Issues: https://github.com/Gormartsen/vue-persist-state/issues
- npm.io page: https://npm.io/package/vue-persist-state

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [xmodel-svelte](https://npm.io/package/xmodel-svelte.md) — 4 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2022-07-18
- 1.0.5 — 2020-02-04
- 1.0.4 — 2020-01-29
- 1.0.3 — 2018-07-19
- 1.0.2 — 2018-05-08
- 1.0.1 — 2018-03-27
- 1.0.0 — 2018-03-27
- 0.1.5 — 2018-03-27
- 0.1.4 — 2018-03-26
- 0.1.3 — 2018-03-22
- 0.1.2 — 2018-03-20
- 0.1.1 — 2018-03-20
- 0.1.0 — 2018-03-20

## README

# vue-persist-state
Vue.$state that is capable to be watched.

State is common for all tabs.
If value changes in one window/tab - it will be updated in others.

`persist:false` variables are available on $state but is not persistent between windows/tabs or page reload.

# usage

```
import PersistState from "vue-persist-state";

// Init global this.$state variable
Vue.use(PersistState, 'myapp-prefix', {
  message: {
    type: 'string',
    default: 'test',
  },
  expireAt: {
    type: 'number',
    default: 0,
  },
  isFirstTime: {
    type: 'boolean',
    default: true,
  }
  isPersistVariable: {
    type: 'boolean',
    default: true,
    persist: false,
  }
});

....


this.$state.message = 'new message';

...

watch: {
  '$state.message': function(newMessage) {
    console.log(newMessage);
  }
}
```

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