0.0.8 • Published 6 years ago

vuex-local-sync v0.0.8

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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.

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago