0.0.21 • Published 3 years ago

pinia-use-persist v0.0.21

Weekly downloads
-
License
-
Repository
-
Last release
3 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

3 years ago

0.0.2

3 years ago

0.0.1-9.1

3 years ago

0.0.19

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.1

3 years ago