Huakun Shen
Huakun Shen

Reputation: 41

How to implement vuex persistence for nuxt.js?

Nuxt version: 2.15.8

I am not initializing vuex the traditional way with Vue.use(Vuex) and new Vuex.Store.

Instead I am doing the nuxt.js way, https://typescript.nuxtjs.org/cookbook/store/#basic-typing.

I don't know how to add plugins for state persistence in this case.

Upvotes: 0

Views: 1068

Answers (1)

Huakun Shen
Huakun Shen

Reputation: 41

This can be achieved with vuex-persist: https://github.com/championswimmer/vuex-persist#tips-for-nuxt

// Inside - nuxt.config.js
export default {
   plugins: [{ src: '~/plugins/vuex-persist.js', mode: 'client' }],
}
// ~/plugins/vuex-persist.js
import VuexPersistence from 'vuex-persist'

export default ({ store }) => {
  new VuexPersistence({
  /* your options */
  }).plugin(store);
}

Upvotes: 1

Related Questions