vuex-local-sync
vuex sync localStoreage or sessionStorage
Last updated 7 months ago by alex2011 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install vuex-local-sync 
SYNC missed versions from official npm registry.

vuex-local-sync

localstorage sync to vuex

usage:

1、 cjs

import Vue from 'vue';

import Vuex from 'vuex';

Vue.use(Vuex);

const VuexLocalSync = require('vuex-local-sync');


const VuxPlugin = new VuexLocalSync.VueLocalSync({
  key: "alex",
  storage: window.localStorage
});

const mutations = {
  setName(state, payload) {
    state.name = payload;
  }
};

const store = new Vuex.Store({
  state: {
    count: 0,
    name: ''
  },
  plugins: [VuxPlugin.plugin],
  mutations: mutations
});

export default store;

2、 esm

import Vue from 'vue';

import Vuex from 'vuex';

Vue.use(Vuex);

import {VueLocalSync} from 'vuex-local-sync'


const VuxPlugin = new VueLocalSync({
  key: "alex",
  storage: window.localStorage
});

const mutations = {
  setName(state, payload) {
    state.name = payload;
  }
};

const store = new Vuex.Store({
  state: {
    count: 0,
    name: ''
  },
  plugins: [VuxPlugin.plugin],
  mutations: mutations
});

export default store;

first, this plugin can sync localStorage(specified key as 'alex') to vuex.

then,when you dispatch the muation(as 'setName' in this example), will sync store.state to localStorage.

Current Tags

  • 0.0.8                                ...           latest (7 months ago)

8 Versions

  • 0.0.8                                ...           7 months ago
  • 0.0.7                                ...           7 months ago
  • 0.0.6                                ...           7 months ago
  • 0.0.5                                ...           7 months ago
  • 0.0.4                                ...           7 months ago
  • 0.0.3                                ...           7 months ago
  • 0.0.2                                ...           7 months ago
  • 0.0.1                                ...           7 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 9
Last Day 0
Last Week 8
Last Month 2
Dependencies (0)
None
Dev Dependencies (11)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |