boenfu / Vuex Along
Licence: mit
📝 A plugins to auto save and restore state for vuex
Stars: ✭ 239
Programming Languages
typescript
32286 projects
Labels
Projects that are alternatives of or similar to Vuex Along
Vuex Persistedstate
💾 Persist and rehydrate your Vuex state between page reloads.
Stars: ✭ 5,561 (+2226.78%)
Mutual labels: vuex, localstorage
Notepad
基于vue2.0+vuex+localStorage+sass+webpack,实现一个本地存储的记事本。兼容PC端和移动端。
Stars: ✭ 597 (+149.79%)
Mutual labels: vuex, localstorage
Vuex Localstorage
Persist Vuex state with expires by localStorage or some else storage.
Stars: ✭ 129 (-46.03%)
Mutual labels: vuex, localstorage
Vue Music Player
🎵Vue.js写一个音乐播放器+📖One(一个).A music player + One by Vue.js
Stars: ✭ 729 (+205.02%)
Mutual labels: vuex, localstorage
Vue Element Starter
Vue starter with Element-UI [READY, unmaintained now]
Stars: ✭ 216 (-9.62%)
Mutual labels: vuex
Awesome Web Storage
😎 Everything you need to know about Client-side Storage.
Stars: ✭ 227 (-5.02%)
Mutual labels: localstorage
Plugin Graphql
Vuex ORM persistence plugin to sync the store against a GraphQL API.
Stars: ✭ 215 (-10.04%)
Mutual labels: vuex
Vuex Easy Firestore
Easy coupling of firestore and a vuex module. 2-way sync with 0 boilerplate!
Stars: ✭ 224 (-6.28%)
Mutual labels: vuex
Angular Cached Resource
An AngularJS module to interact with RESTful resources, even when browser is offline
Stars: ✭ 218 (-8.79%)
Mutual labels: localstorage
Vuex Router Sync
Effortlessly keep vue-router and vuex store in sync.
Stars: ✭ 2,499 (+945.61%)
Mutual labels: vuex
Vuex Typescript
A simple way to make Vuex type-safe with intuitive intellisense
Stars: ✭ 234 (-2.09%)
Mutual labels: vuex
Array Explorer
⚡️ A resource to help figure out what JavaScript array method would be best to use at any given time
Stars: ✭ 2,512 (+951.05%)
Mutual labels: vuex
Canvas Sketch
App to sketch out a business model canvas
Stars: ✭ 232 (-2.93%)
Mutual labels: localstorage
English | 简体中文
vuex-along - 持久化存储 state 的 vuex 扩展
常用于刷新网页后自动恢复 state
目录
安装
npm install vuex-along --save
# or
yarn add vuex-along
用法
import createVuexAlong from 'vuex-along'
export default new Vuex.Store({
state:{...},
modules:{...},
plugins: [createVuexAlong()]
});
到此为止,插件已经生效了,默认会存储所有 state 到 localStorage
传入需要的 参数 来满足使用需求
示例
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({
// 设置保存的集合名字,避免同站点下的多项目数据冲突
name: "hello-vuex-along",
local: {
list: ["ma"],
// 过滤模块 ma 数据, 将其他的存入 localStorage
isFilter: true,
},
session: {
// 保存模块 ma 中的 a1 到 sessionStorage
list: ["ma.a1"],
},
}),
],
});
参数
VuexAlongOptions
字段 | 必选 | 类型 | 描述 |
---|---|---|---|
name | 否 | String | 设置本地数据集合的名字,默认为 vuex-along |
local | 否 | Object | localStorage 的配置,见 #WatchOptions |
session | 否 | Object | sessionStorage 的配置,见 #WatchOptions |
justSession | 否 | Boolean | 仅使用 sessionStorage |
WatchOptions
字段 | 必选 | 类型 | 描述 |
---|---|---|---|
list | 是 | String [] | 需要监听的属性名或模块名的字符串列表 |
isFilter | 否 | Boolean | 过滤 list 中的字段而非保存 |
数据清理
window.clearVuexAlong(local = true, session = true):void;
clearVuexAlong() // localStorage 和 sessionStorage 都会被清理
clearVuexAlong(true,false) // 只清理 localStorage
clearVuexAlong(false,true) // 只清理 sessionStorage
运行 demo
git clone https://github.com/boenfu/vuex-along.git
cd ./vuex-along
yarn run:demo
提示项
- 支持
typescript
-
IE11
可用 -
sessionStorage
数据恢复优先级高于localStorage
- 存储内容的顶层对象的
key
固定为root
贡献者们
|
维护者
License
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].