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 };
});
This worked for me
Store/index.js
...
state: {
loadedPages: []
}
...
Page
async asyncData(context) {
...
console.log(context.store.state.loadedPages)
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With