pinia-plugin-persist
Persist pinia state data storages.
installation
npm install @jswork/pinia-plugin-persist
usage
import PiniaPluginPersist from '@jswork/pinia-plugin-persist';
// ======== main.js ======
export function createApp() {
const app = createSSRApp(App);
const pinia = createPinia();
// Attach storage
app.$storage = nx.$storage;
pinia.use(PiniaPluginPersist);
//...
}
// ======== stores/auth.js ======
import { defineStore } from "pinia";
export default defineStore("auth", {
state: () => ({ profile: null, user: null, other: null }),
persist: {
keys: ["profile", "user"]
},
});
license
Code released under the MIT license.