O
O
Ockonal2020-05-31 23:38:38
Vue.js
Ockonal, 2020-05-31 23:38:38

How to save vuex state between transitions in nuxtjs?

I have a Nuxtjs application in SSR mode. In it, the vuex state is reset on any change in the route. I want to keep it. To do this, there are a couple of plugins that save the state in localstorage and restore it. The problem is only in the order of its restoration

. For example, I want to draw data in the template, I call the vuex action in the fetch method:

async fetch({ store, route }) {
    await store.dispatch("items/fetch_exact", route.params.slug);
  }


Problem : All fetch + dispatch requests happen before the persisted state plugin is initialized and synchronizes the state from localstorage. This means that inside any logic from fetch, my state will still be empty. How to force fetch to wait until the state is restored from localstorage?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question