Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State not being restored. #13

Closed
lordzouga opened this issue Nov 15, 2017 · 4 comments
Closed

State not being restored. #13

lordzouga opened this issue Nov 15, 2017 · 4 comments

Comments

@lordzouga
Copy link

lordzouga commented Nov 15, 2017

I have a list of objects that is stored in vuex. I have setup vuex-persist as instructed but on startup, it doesn't auto restore the state.

I have an action that runs every time the app is started, this action fetches data based on a variable that should be persisted with vuex-persist.

    loadJobs: function ({ commit }) {
      axios({
          method: 'get',
          url: 'http://localhost:9000/document/jobs',
          headers: {'X-BB-SESSION': 'secret-string'},
          params: {
            where: 'timeposted > ' + this.state.lastUpdate //this should have persisted value,
            page: 0,
            recordsPerPage: 50
          }
      })
      .then((response) => {
        if (response.data.data.length > 0){
           console.log(this.state.lastUpdate) // weirdly has the persisted value here
          commit('setJobs', { list: response.data.data })
        }
        commit('setLastUpdateTime', Math.floor(Date.now() / 1000));
      })
      .catch((error) => {
          console.log(error)
      })
  }

inside the response callback of the axios request, this.state.lastUpdate seems to have the right persisted value. other state attributes have this behavior as well.

my question being, when is the state being restored? is there a special scope needed before it can be accessed?

in some cases, I have to mutate a certain state before the persisted version is read by the bound vue component.

Any help will be appreciated. I feel as if I am missing something obvious here

@championswimmer
Copy link
Owner

could you show the source of your vuex store entry point

@msaelices
Copy link

msaelices commented Nov 26, 2017

Maybe this would help. I had the same problem and this could be a workaround.

Place the following in the component which paints the persisted data:

mounted() {
  setTimeout(() => {
    this.$forceUpdate();
  }, 100);
},

@msaelices
Copy link

If you want to know about my fix context. See msaelices/vue-onsenui-weather@d34395b

@championswimmer
Copy link
Owner

this is the same problem as #15

it has been fixed in v1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants