nuxt的asyncData函数中如何访问vue store
How to access to the vue store in the asyncData function of nuxt
在一个组件中,我想像这样使用 asyncData 函数访问商店:
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 };
});
}
但我收到了 "Cannot read property 'state' of undefined"
这里有没有另一个可以接收store状态的?
您需要从上下文中获取存储。 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 };
});
这对我有用
Store/index.js
...
state: {
loadedPages: []
}
...
第
页
async asyncData(context) {
...
console.log(context.store.state.loadedPages)
...
}
在一个组件中,我想像这样使用 asyncData 函数访问商店:
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 };
});
}
但我收到了 "Cannot read property 'state' of undefined"
这里有没有另一个可以接收store状态的?
您需要从上下文中获取存储。 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 };
});
这对我有用
Store/index.js
...
state: {
loadedPages: []
}
...
第
页async asyncData(context) {
...
console.log(context.store.state.loadedPages)
...
}