0.0.21 • Published 2 years ago

pinia-use-persist v0.0.21

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Documentation

Install

npm i pinia-use-persist

Use

main.ts

import {createPinia} from "pinia";

import {usePersist} from 'pinia-use-persist'

const pinia = createPinia()

pinia.use(usePersist)

app.use(pinia)

store.ts

export const useStore = defineStore('main', {
  state: () => ({
    counter: 0,
  }),
  persist:{
    enabled: true,
    key: ['counter'],
    encryptionKey: 'my-store',
    storage: sessionStorage,
  }
})
<script setup lang='ts'>
import { useStore } from '@/store/store.ts'
const store = useStore()

const add = () => {
  store.$patch((state) => {
    state.counter = state.counter + 1
  })
}
</script>

<template>
  <div>
    <p>{{store.$state.counter}}</p>
    <button @click="add">+</button>
  </div>
</template>

Note: 📢

When you add new key-value in store.ts file, you need to reload the page to achieve persistence.

Plan 📢

  1. Logger
  2. Encryption
  3. ...
0.0.21

2 years ago

0.0.2

2 years ago

0.0.1-9.1

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.1

2 years ago