如何在nuxt的asyncData函数中访问vue store [英] How to access to the vue store in the asyncData function of nuxt

查看:545
本文介绍了如何在nuxt的asyncData函数中访问vue store的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个组件中,我想使用 asyncData 函数访问商店,如下所示:

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 ?

推荐答案

您需要从上下文中获取存储.参考

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 };
});

这篇关于如何在nuxt的asyncData函数中访问vue store的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆