vuex vuex-persist 로 특정 모듈만 로컬스토리지에 저장하기

acctto·2022년 4월 28일
0

vuex-persist 라이브러리를 활용해 특정 모듈만 로컬스토리지에 저장하고 싶었다. 다음과 같이 하면 되는 것 같다.
(auth 라는 모듈이 있다고 가정한다)

import Vue from 'vue';
import Vuex from 'vuex';
import auth from './modules/auth';
import VuexPersistence from 'vuex-persist';

Vue.use(Vuex);

const vuexLocal = new VuexPersistence({
  storage: window.localStorage,
  modules: ['auth'],
});

export default new Vuex.Store({
  modules: {
    auth,
  },
  plugins: [vuexLocal.plugin],
});
profile
Nice

0개의 댓글