Skip to content

本地持久化存储vuex,使得页面状态保存,多窗口之间共享

Notifications You must be signed in to change notification settings

DOBEEE/vuex-crossviews-shared

Repository files navigation

vuex-crossviews-shared

vuex跨窗口共享插件

支持移动端多webview页面vuex共享

NPM version NPM downloads

依赖

安装

npm install --save vuex-crossviews-shared

使用

import sharedVuex from 'vuex-crossviews-shared'

const store = new Vuex.Store({
  // ...
  plugins: [sharedVuex()],
})

API

sharedVuex([options])

  • key <String>: storage存储的key. (default: h5_vuex)
  • paths <Array>: 需要持久化存储的state数据.例:['a.b.c', 'a.b.d'] (default: [])
  • filter <Function>: 对触发storage更新的commit筛选方法(default: ()=>true).如:
    filter = (mutation) => {
      if (mutation.type === 'example') {
         return true;
      }
    };
    
    唯一参数是mutation对象
  • event <Object>: 自定以事件方法,用来做发布和响应自定义事件. (default: localstorage的原生监听事件,可能在ios上的UIWebView中失效) 它应包含三个方法:
    //发布事件
    event.emit({
         type: key,
         data: state,
    });
    //取消事件
    event.off({
     type: key,
     handler: window._vuexhandle,
    });
    //注册事件
    event.on({
     type: key,
         handler: window._vuexhandle,
    });

About

本地持久化存储vuex,使得页面状态保存,多窗口之间共享

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published