35

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 ?

2 Answers 2

54

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 };
});
Sign up to request clarification or add additional context in comments.

Comments

2

This worked for me

Store/index.js

...

state: {
  loadedPages: []
}
...

Page

async asyncData(context) {
...
console.log(context.store.state.loadedPages)
...

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.