persistia
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

persistia

Persist Pinia state data in localStorage

npm version license

Installation

Install with your favourite package manager:

# yarn
yarn add persistia

# pnpm
pnpm add persistia

# npm
npm install persistia

Import and install:

// main.js
import { createPinia } from 'pinia'
import { persistia } from 'persistia'

const pinia = createPinia()
pinia.use(persistia)

Enable the plugin per store:

import { defineStore } from 'pinia'

export const useStore = defineStore('...', {
  persist: true,

  state: () => ({ ... }),

  actions: { ... },

  getters: { ... }
})

Alternatively, you can specify which keys in state to persist:

import { defineStore } from 'pinia'

export const useStore = defineStore('...', {
  persist: ['name', 'age'],

  state: () => ({
    name: 'Jane Doe',
    age: 42,
    email: 'jane@example.com',
    address: '123 Fake St.'
  }),

  actions: { ... },

  getters: { ... }
})

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i persistia

Weekly Downloads

3

Version

1.1.0

License

MIT

Unpacked Size

5.45 kB

Total Files

7

Last publish

Collaborators

  • happytiptoe