pinia-persistedstate-plugin

A pinia plugin like vuex-persistedstate.
8,546
Install
npm install pinia-persistedstate-plugin
Latest Version:0.1.0
License:MIT
Last Updated:Mar 31, 2022
Links: npm
Maintainer: l-x-f

pinia-persistedstate-plugin

English | 中文

A pinia plugin like vuex-persistedstate.

Install

npm install pinia-persistedstate-plugin

or

yarn add pinia-persistedstate-plugin

or

pnpm add pinia-persistedstate-plugin

The UMD build is also available on unpkg:

<script src="https://unpkg.com/pinia-persistedstate-plugin/dist/pinia-persistedstate-plugin.umd.js"></script>

You can find the library on window.PiniaPersistedstatePlugin.

Usage

In main.ts:

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { createPersistedState } from 'pinia-persistedstate-plugin'
import App from './App.vue'

const app = createApp(App)
const store = createPinia()

store.use(createPersistedState())

app.use(store).mount('#app')

use js-cookie

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { createPersistedState } from 'pinia-persistedstate-plugin'
import App from './App.vue'
import Cookies from 'js-cookie'

const app = createApp(App)
const store = createPinia()

store.use(
  createPersistedState({
    storage: Cookies
  })
)

app.use(store).mount('#app')

Options

export interface Options {
  /**
   * storage, default is `window.localStorage`
   *
   * support `js-cookie` `window.localStorage` `window.sessionStorage`
   */
  storage?: Storage | Cookies
  /**
   * storage key prefix, default is `pinia`
   */
  key: string
  /**
   * is open logger, default is `false`
   */
  logger: boolean
}

License

MIT License.

Related Packages

pinia-plugin-loading

Auto loading data binding plugin for pinia. You don't need to write showLoading...

1,337 12
pinia-plugin-created

create created lifecycle method in your pinia 🍍 store!

284 0
pinia-plugin-router

A pinia plugin that help use vue-router in pinia

4,356
pinia-persistedstate

For vue3. Persist and rehydrate your Pinia state between page reloads.

3,857 15
pinia-plugin-firestore-sync

Sync your pinia state and firestore document at ease!

442

Version History

Version Released License
0.1.0 MIT
0.0.9 MIT
0.0.8 MIT
0.0.7 MIT
0.0.6 MIT