Skip to content

fullStackDemo/vuex-local-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

localstorage sync to vuex

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published