Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

💾 Configurable persistence and rehydration of Pinia stores.

License

NotificationsYou must be signed in to change notification settings

prazdevs/pinia-plugin-persistedstate

Repository files navigation

Pinia Plugin Persistedstate

Configurable persistence and rehydration of Pinia stores.

npmminizipped sizelicense

Documentation

Features

  • Persist Pinia stores with a friendly API inspired byvuex-persistedstate.
  • Highly customizable (storage, serializer, paths picking/omitting).
  • Out of the box SSR-friendly support forNuxt.
  • Very smol (<2kB minzipped).

Quickstart

  1. Install with your favorite package manager:

    • pnpm :pnpm add pinia-plugin-persistedstate
    • npm :npm i pinia-plugin-persistedstate
    • yarn :yarn add pinia-plugin-persistedstate
  2. Add the plugin to pinia:

import{createPinia}from'pinia'importpiniaPluginPersistedstatefrom'pinia-plugin-persistedstate'constpinia=createPinia()pinia.use(piniaPluginPersistedstate)
  1. Add thepersist option to the store you want to be persisted:
import{defineStore}from'pinia'exportconstuseStore=defineStore('store',{state:()=>({someState:'hello pinia',}),persist:true,})

Configuration

You can configure how a store is persisted by specifying options to thepersist property:

exportconstuseStore=defineStore('store',()=>{constsomeState=ref('hello pinia')return{ someState}},{persist:{storage:sessionStorage,pick:['someState'],},})

All the available configuration options are explainedhere.

Usage with Nuxt

Nuxt support comes out of the box thanks to the included module. You just need to install the package and add the module to yournuxt.config.ts as follows:

exportdefaultdefineNuxtConfig({modules:['@pinia/nuxt',// required'pinia-plugin-persistedstate/nuxt',],})

More information on storages and configuration in Nuxthere.

Limitations

There are several limitations that should be considered, more on thosehere.

Contributing

See thecontribution guide.

License

MIT © 2021-presentSacha Bouillez


[8]ページ先頭

©2009-2025 Movatter.jp