Static GitHub Issues

[492] Feed store state with async data at application start

prev: How to set up Nuxt.js with Nginx
next: Nuxt can be multi-process webpack package?

Hey there,

I am getting started with Vuex and Nuxt (which really is awesome) and I am facing a problem for hours.

My application is an Electron one. Basically what I want to do is stated in the title. I'll give some code for it to be more clear.

What I want to do is feeding store.state.randomVariable with some async data on application start.

My method is a promise. This is what I would like to do.

// At start
getLatest().then((items) => {
  store.state.releases = items
}

As those data would not be hear on page rendering, I should then see them app on my html as if I would do it with basic Vue and without reloading of course with something like this:

let vm = new Vue({
  el: '#some-element',
  data: {
    releases: []
  }
})

getLatest().then((items) => {
  vm.releases = items
})

I tried working with middleware and some other things but I could not get it working. I would really appreciate a hand on this.

Thank you!

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c429">#c429</a>)</em></sub></div>