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

0.1.0 • Public • Published

pinia-persist

This package works for Vue 2 & 3 by the power of Vue Demi!

Getting Started

Installation

NPM

$ npm i pinia-persist # yarn add pinia-persist

CDN

<script src="https://unpkg.com/pinia-persist"></script>

Usage

import { ref } from 'vue' // import { ref } from '@vue/composition-api'
import { createPinia, defineStore } from 'pinia'
import { createPersistPlugin } from 'pinia-persist'

const pinia = createPinia()
pinia.use(createPersistPlugin())

const useCounterStore = defineStore(
  'counter-store',
  () => {
    return {
      count: ref(0),
    }
  },
  { persist: { storage: window.localStorage } },
)
// const counterStore = defineStore('counter-store', {
//   state() {
//     return { count: 0 }
//   },
//   persist: { storage: window.localStorage },
// })

const counterStore = useCounterStore()
counterStore.count++ // fires window.localStorage.setItem('counter-store', JSON.stringify({ count: 0 }))

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

This project use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MIT License - see the LICENSE file for details

/pinia-persist/

    Package Sidebar

    Install

    npm i pinia-persist

    Weekly Downloads

    43

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    20.2 kB

    Total Files

    15

    Last publish

    Collaborators

    • iendeavor