Coder Social home page Coder Social logo

xinlong-chen865 / vuex-persist-plugin Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 0.0 88 KB

vuex-persist-plugin是一个vuex的插件,支持vuex4以及ts。此插件配置项非常简单,只需要告知插件storage的名字、需要保存的state以及storage的种类(支持localstorage、sessionstorage)即可

JavaScript 6.45% TypeScript 93.55%

vuex-persist-plugin's Introduction

功能

vuex-persist-plugin是一个vuex的插件,支持vuex4以及ts。此插件配置项非常简单,只需要告知插件storage的名字、需要保存的state以及storage的种类(支持localstorage、sessionstorage)即可

用法

支持保存整个module的数据,并支持保存module中某一个state的数据

import { createStore } from 'vuex'
import VuexPersister from "vuex-persist-plugin-ts";

const vuexPersister = new VuexPersister({
  key: 'my_key',
  saveParams: ['count', 'A.number'],
});

export default createStore({
  state: {
    count: 0,
    age: 0,
  },
  modules: {
    A: {
      namespaced: true,
      state: {
        number: 0,
      },
    }
  },
  plugins: [
    vuexPersister.bootstrap,
  ]
})



配置项

参数名 可选值 含义 默认值
storage localstorage / sessionstorage / 空 storage种类 localstorage
saveParams ['username', 'music.musicName'] / 空 需要加缓存的路径 []
key 'my-vuex' / 空 缓存key的命名 'vuex-persist-plugin'

vuex-persist-plugin's People

Stargazers

Carl Tong avatar Sun avatar 海外散修厉飞雨 avatar  avatar _mdd avatar Laoce avatar

Watchers

Laoce 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.