How to access to the vue store in the asyncData function of nuxt

泪湿孤枕 提交于 2019-12-23 07:28:46

问题


in a component i want to acces to the store with the asyncData function like so :

asyncData({ app, params }) {
var url = `https://myapi/news/${app.$store.state.market}/detail/${params.id}`;
return app.$axios.get(url).then(response => {
  return { actu: response.data };
});

}

but i received "Cannot read property 'state' of undefined"

is there another to receive the state of the store here ?


回答1:


You need to get store from context. Reference

asyncData({ app, params, store }) {
   var url = `https://myapi/news/${store.state.market}/detail/${params.id}`;
   return app.$axios.get(url).then(response => {
      return { actu: response.data };
});


来源:https://stackoverflow.com/questions/51556126/how-to-access-to-the-vue-store-in-the-asyncdata-function-of-nuxt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!