{"action":"created","issue":{"url":"https://api.github.com/repos/nuxt/nuxt.js/issues/492","repository_url":"https://api.github.com/repos/nuxt/nuxt.js","labels_url":"https://api.github.com/repos/nuxt/nuxt.js/issues/492/labels{/name}","comments_url":"https://api.github.com/repos/nuxt/nuxt.js/issues/492/comments","events_url":"https://api.github.com/repos/nuxt/nuxt.js/issues/492/events","html_url":"https://github.com/nuxt/nuxt.js/issues/492","id":218693472,"number":492,"title":"Feed store state with async data at application start","user":{"login":"Kylart","id":18316666,"avatar_url":"https://avatars1.githubusercontent.com/u/18316666?v=3","gravatar_id":"","url":"https://api.github.com/users/Kylart","html_url":"https://github.com/Kylart","followers_url":"https://api.github.com/users/Kylart/followers","following_url":"https://api.github.com/users/Kylart/following{/other_user}","gists_url":"https://api.github.com/users/Kylart/gists{/gist_id}","starred_url":"https://api.github.com/users/Kylart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kylart/subscriptions","organizations_url":"https://api.github.com/users/Kylart/orgs","repos_url":"https://api.github.com/users/Kylart/repos","events_url":"https://api.github.com/users/Kylart/events{/privacy}","received_events_url":"https://api.github.com/users/Kylart/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2017-04-01T12:43:32Z","updated_at":"2017-04-02T14:50:40Z","closed_at":null,"body":"Hey there, \r\n\r\nI am getting started with Vuex and Nuxt (which really is awesome) and I am facing a problem for hours. \r\n\r\nMy 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.\r\n\r\nWhat I want to do is feeding `store.state.randomVariable` with some async data on application start.\r\n\r\nMy method is a promise. This is what I would like to do.\r\n```javascript\r\n// At start\r\ngetLatest().then((items) => {\r\n  store.state.releases = items\r\n}\r\n``` \r\n\r\nAs 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:\r\n\r\n```javascript\r\nlet vm = new Vue({\r\n  el: '#some-element',\r\n  data: {\r\n    releases: []\r\n  }\r\n})\r\n\r\ngetLatest().then((items) => {\r\n  vm.releases = items\r\n})\r\n```\r\n\r\nI tried working with middleware and some other things but I could not get it working. I would really appreciate a hand on this.\r\n\r\nThank you!"},"comment":{"url":"https://api.github.com/repos/nuxt/nuxt.js/issues/comments/290991163","html_url":"https://github.com/nuxt/nuxt.js/issues/492#issuecomment-290991163","issue_url":"https://api.github.com/repos/nuxt/nuxt.js/issues/492","id":290991163,"user":{"login":"ausir0726","id":7247064,"avatar_url":"https://avatars2.githubusercontent.com/u/7247064?v=3","gravatar_id":"","url":"https://api.github.com/users/ausir0726","html_url":"https://github.com/ausir0726","followers_url":"https://api.github.com/users/ausir0726/followers","following_url":"https://api.github.com/users/ausir0726/following{/other_user}","gists_url":"https://api.github.com/users/ausir0726/gists{/gist_id}","starred_url":"https://api.github.com/users/ausir0726/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ausir0726/subscriptions","organizations_url":"https://api.github.com/users/ausir0726/orgs","repos_url":"https://api.github.com/users/ausir0726/repos","events_url":"https://api.github.com/users/ausir0726/events{/privacy}","received_events_url":"https://api.github.com/users/ausir0726/received_events","type":"User","site_admin":false},"created_at":"2017-04-02T14:50:40Z","updated_at":"2017-04-02T14:50:40Z","body":"@Kylart  yes , maybe ... \r\nI think this is just a one way to resolve you problem .\r\nyou also can working with vuex store .\r\n\r\nbut nuxtServerInit only run on SSR ( npm build )\r\nif you want fetch data when open you electron app you should modify\r\n\r\n```js\r\n// store/index.js\r\nimport Vue from  'vue'\r\nimport Vuex from 'vuex'\r\nimport axios from 'axios'\r\n\r\nVue.use(Vuex)\r\n\r\nconst store = new Vuex({\r\n  state : {\r\n    seasons: []\r\n  },\r\n  mutations : {\r\n    setSeasons: function (state, data) {\r\n      state.seasons = data\r\n    }\r\n  },\r\n  actions = {\r\n    async browserInit({commit}) {\r\n      const { data } = await axios.get(`malScraper.json?year=2016&season=fall`)\r\n      commit('setSeasons', data )\r\n    }\r\n  }\r\n})\r\n\r\nstore.dispatch('browserInit');\r\n\r\nexport default store ;\r\n\r\n```\r\n\r\n```vue\r\n<template>\r\n  <div>\r\n    <h1>Welcome!</h1>\r\n    <nuxt-link to=\"/about\">About page</nuxt-link>\r\n    <ul v-if=\"seasons.length\">\r\n      <li v-for=\"item in $store.state.seasons\">title : {{item.title}}</li>\r\n    </ul>\r\n    <div v-else>\r\n      <p>mal-scraper is on fetching data... please wait..</p>\r\n    </div>\r\n  </div>\r\n</template>\r\n\r\n<script>\r\nexport default {\r\n  data() {\r\n  },\r\n};\r\n</script>\r\n```\r\n\r\nI didn't try this code , but it should work ...\r\nseen you almost there ....\r\n\r\n"}}
{"actor":{"display_login":"ausir0726"}}