问题
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