DEV Community

Discussion on: Use Bulma and FontAwesome 5 with Nuxt.js

Collapse
 
lewiskori profile image
Lewis kori

This is really awesome. nuxt is really heaven-sent. Thanks for sharing. Do you have any resources on persisting vuex data on page refresh?

Collapse
 
mtpiercey profile image
Matthew Piercey

You're in luck - here you go:

// ~/plugins/vuex-persistence.js
// npm install --save vuex-persistedstate or yarn add vuex-persistedstate
import createPersistedState from 'vuex-persistedstate'
/*
  This little plugin is the surprisingly-easy way to make Vuex stuff persist in
  a user's browser's localStorage. Super useful.
*/

export default ({ store, isHMR }) => {
  if (isHMR) { return }

  window.onNuxtReady((nuxt) => {
    createPersistedState()(store)
  })
}

Just import this sucker in nuxt.config.js like so:

plugins: [
'~/plugins/vuex-persistence

]

Collapse
 
lewiskori profile image
Lewis kori

thank you. This worked like a charm. Looking forward to reading more from you!