1.2.13 • Published 3 years ago

vuex-along v1.2.13

Weekly downloads
242
License
MIT
Repository
github
Last release
3 years ago

English | 简体中文

Directory

Install

npm install vuex-along --save
# or
yarn add vuex-along

Usage

import createVuexAlong from 'vuex-along'

export default new Vuex.Store({
  state:{...},
  modules:{...},
  plugins: [createVuexAlong()]
});

Now, the plugin has been in effect, and all state is stored to localStorage by default.

Set Options to meet the usage requirements

Example

→ Online Example

import createVuexAlong from "vuex-along";

const moduleA = {
  state: {
    a1: "hello",
    a2: "world",
  },
};

const store = new Vuex.Store({
  state: {
    count: 0,
  },
  modules: {
    ma: moduleA,
  },
  plugins: [
    createVuexAlong({
      //Set the collection name to avoid multi-project data conflicts with the same site
      name: "hello-vuex-along",
      local: {
        list: ["ma"],
        // Filter the module ma data, save the other to localStorage
        isFilter: true,
      },
      session: {
        // Save a1 in module ma to sessionStorage
        list: ["ma.a1"],
      },
    }),
  ],
});

Options

VuexAlongOptions

FieldRequiredTypeDescription
namenoStringSet the name of the local data collection, the default is vuex-along
localnoObjectLocalStorage configuration, see #WatchOptions
sessionnoObjectSessionStorage configuration, see #WatchOptions
justSessionnoBooleanUse only sessionStorage

WatchOptions

FieldRequiredTypeDescription
listyesString []List of strings of attribute names or module names that need to be listened to
isFilternoBooleanFilter fields in list instead of saving

Cleanup

window.clearVuexAlong(local = true, session = true):void;
clearVuexAlong() // localStorage and sessionStorage will be cleaned up
clearVuexAlong(true,false) // Just localStorage
clearVuexAlong(false,true) // Just sessionStorage

RunDemo

git clone https://github.com/boenfu/vuex-along.git
cd ./vuex-along
yarn run:demo

Tips

  • Support typescript
  • Support IE11
  • sessionStorage data recovery takes precedence over localStorage
  • The key of the top-level object that stores the content is fixed to root

Contribution

Maintainers

License

1.2.13

3 years ago

1.2.12

3 years ago

1.2.11

4 years ago

1.2.10

4 years ago

1.2.9

4 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.1.5

5 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago