4

I use vuex-persistedstate package (https://github.com/robinvdvleuten/vuex-persistedstate) to persist data state on browser.

I use Adonuxt (a mix between NuxtJS and AdonisJS).

In VueX actions, I have this action:

nuxtClientInit ({commit}) {
      // I want get here state auth saved by persistedstate package
    }

This action is called by plugin:

localstorage.js

export default async (context) => {
  await context.store.dispatch('nuxtClientInit', context)
}

nuxt.js plugin (config)

{
      src: '~/plugins/localstorage.js',
      ssr: false
    }

I want get state to configure Axios with the user token:

this.$axios.setToken(auth.jwt.token, 'Bearer')

I have the impression nuxtClientInit() is called before persistedstate package, so state.auth is null but it can observable in console:

image

pirmax
  • 1,508
  • 5
  • 21
  • 53

2 Answers2

4

I've used https://www.npmjs.com/package/vuex-persist to persist data from Vuex.

pirmax
  • 1,508
  • 5
  • 21
  • 53
0

In my case, I made a mistake in specifying the directory.

root/
 ├ src/
 ├ pages/
     .
     .
 ├ src/
   └ plugins/
     └ localstorage.js/

In the above directory, you must specify as follows.

In nuxt.config.js

{src:'~/src/plugins/localstorage.js', srr: false}