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

1.2.0 • Public • Published

Pinia Persists

A pinia plugin for state persist.

NPM version

English | 简体中文

Usage

Install

npm i pinia-persists

Use

import { persist } from 'pinia-persists'
import { createPinia } from 'pinia'

const pinia = createPinia()

// pinia use plugin
pinia.use(persist({ /* options */ }))

app.use(pinia)

Options

prefix

  • type: String
  • optional, default "pinia"
  • it is the prefix of the key to store the persisted state under, such as the store id is "test", that store key is "pinia_test" by default.

storage

  • type: Object

    interface Storage {
        readonly length?: number;
        clear?: () => void;
        getItem: (key: string) => string | null;
        key?: (index: number) => string | null;
        removeItem?: (key: string) => void;
        setItem: (key: string, value: string) => void;
        [name: string]: any;
    }
  • optional, default window.localStorage

  • it is the storage for state persist, you can choose localStorage, sessionStorage or your custom storage.

overwrite

  • type: Boolean
  • optional, default false
  • when app first loader or refresh, whether to overwrite the existing state with the output from state directly, instead of merging the two objects with deep merge.

License

MIT License © 2022 Dewey Ou

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.2.0
    21
    • latest

Version History

Package Sidebar

Install

npm i pinia-persists

Weekly Downloads

21

Version

1.2.0

License

MIT

Unpacked Size

6.94 kB

Total Files

5

Last publish

Collaborators

  • ouduidui