Skip to content

Configuration

Global Configuration

The pinia-plugin-state-persistence accepts a global configuration object passed to createStatePersistence with the following properties:

PropertyTypeDescription
keystringKey used as a prefix for all store keys when persisting data. Defaults to the store’s ID if not provided at the store level. This is a global configuration property.
debugbooleanEnables logging for debugging purposes. Defaults to false.
overwritebooleanWhether to overwrite the store state on $restore. Defaults to false.
clientOnlybooleanDetermines if storage operations should be restricted to the client environment only. Defaults to false.
storageStorage | AsyncStorageStorage mechanism for persisting data. Supports synchronous (e.g., localStorage) and asynchronous options (e.g., localForage).
filter(mutation, state) => booleanFilters which mutations trigger persistence.
serialize(state) => stringCustom function for serializing the state.
deserialize(state: string) => Partial<S>Custom function for deserializing the state.
deepCopybooleanEnsure a deep copy of the state by serializing and deserializing. Store the state as an object while avoiding issues with unsupported values like functions or circular references.

Global Configuration Default Behavior

If no global options are provided, the plugin uses the following defaults:

ts
import { 
createStatePersistence
} from 'pinia-plugin-state-persistence'
createStatePersistence
({
key
: '', // Acts as a prefix for all store keys when persisting data
debug
: false, // Debugging disabled
overwrite
: false, // Do not overwrite existing state
storage
:
localStorage
, // Use localStorage by default
serialize
:
JSON
.
stringify
, // Default serialization
deserialize
:
JSON
.
parse
, // Default deserialization
deepCopy
: false, // Default deepCopy
})

Store Configuration

For configuring individual stores, refer to the PersistOptions documentation, which outlines properties for store-level customization.