Skip to content

Instantly share code, notes, and snippets.

@alifrizkip
Created August 22, 2020 13:53
Show Gist options
  • Save alifrizkip/f9b23f37dd52263f39ebc9811213d079 to your computer and use it in GitHub Desktop.
Save alifrizkip/f9b23f37dd52263f39ebc9811213d079 to your computer and use it in GitHub Desktop.
index-secure-ls-persistedstate.js
import Vue from 'vue';
import Vuex from 'vuex';
import createPersistedState from 'vuex-persistedstate';
import SecureLS from "secure-ls";
import cart from './modules/cart';
Vue.use(Vuex);
const secureLS = new SecureLS({
encodingType: 'aes',
encryptionSecret: 'vue-cart-persist'
});
const cartState = createPersistedState({
key: 'cart-persist-state',
paths: ['cart.carts'],
storage: {
getItem: (key) => secureLS.get(key),
setItem: (key, value) => secureLS.set(key, value),
removeItem: (key) => secureLS.remove(key),
},
});
const store = new Vuex.Store({
modules: {
cart,
},
plugins: [cartState],
});
export default store;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment