Giter Site home page Giter Site logo

neocjz / pinia-plugin-persistedstate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from prazdevs/pinia-plugin-persistedstate

0.0 0.0 0.0 5.03 MB

Pinia的持久化插件——🍍 Configurable persistence and rehydration of Pinia stores.

Home Page: https://prazdevs.github.io/pinia-plugin-persistedstate

License: MIT License

TypeScript 100.00%

pinia-plugin-persistedstate's Introduction

Artwork from Pinia

pinia-plugin-persistedstate

Configurable persistence and rehydration of Pinia stores.

npm CI Coverage License

English | 简体中文

✨ Features

  • Persist Pinia stores with a friendly API inspired by vuex-persistedstate.
  • Highly customisable with custom storage, customer serializer, paths picking...
  • Compatible with everything that uses Pinia.
  • No external dependencies in a tiny package (<1kB gzipped).

🚀 Quickstart

  1. Install with your favorite package manager:

    • pnpm : pnpm i pinia-plugin-persistedstate
    • npm : npm i pinia-plugin-persistedstate
    • yarn : yarn add pinia-plugin-persistedstate
  2. Add the plugin to pinia:

import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'

const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
  1. Add the persist option to the store you want to be persisted:
import { defineStore } from 'pinia'

export const useStore = defineStore('store', {
  state: () => {
    return {
      someState: 'hello pinia',
    }
  },
  persist: true,
})

🔧 Configuration

You can configure how a store is persisted by specifying options to the persist property:

import { defineStore } from 'pinia'

export const useStore = defineStore('store', {
  state: () => {
    return {
      someState: 'hello pinia',
    }
  },
  persist: {
    storage: sessionStorage,
    paths: ['someState'],
  },
})

All the available configuration options are explained here.

⚠️ Limitations

There are some limitations that should be considered, more on those here.

🤝 Contributing

Run into a problem? Open an issue. Want to add some feature? PRs are welcome!

👤 About the author

Feel free to contact me:

twitter: @prazdevs

📝 License

Copyright © 2021-present Sacha Bouillez.
This project is under MIT license.

pinia-plugin-persistedstate's People

Contributors

prazdevs avatar n0texisting avatar cloudmoonocus avatar megasu avatar xucxichcao avatar wukong-c avatar markthree avatar lvsong77 avatar floriankapaun avatar ajenkins-cargometrics avatar toniengelhardt avatar tobymosque avatar sevsev9 avatar proton avatar ivanq3w avatar hooray avatar furkan-guvenc avatar emory-m avatar lakuapik avatar chris-si avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.