Trying to reach article's id and fetch it. But in somewhere I do some mistakes. Because vuex returns empty object and router-link is fails.
so far, I made some something like below.
state: { article: {}, }, getters: { bringArticle(state){ return state.article; } }, mutations: { updateArticle(state, article){ state.article = article; } }, actions: { getArticle(context, id){ axios.get("/api/articles/" + id) .then((response) => { context.commit("updateArticle", response.data); console.log(response.data) }) .catch((error) => { console.log(error); }) } } Clearly this axios.get("/api/articles/" + id) is not working out...
by the way. I see id's data at the endpoint without a problem. Just stuck the axios part. How can I reach the id?
Route::get("/articles/{id}", "Api\ArticlesController@singleArticle");
dispatch('getArticle')to get the article? it should be something likethis.$store.dispatch('getArticle', 1);from within a component, with1being the id you want to load.getArticle(context, { id })or change the way you call dispatch tothis.$store.dispatch('getArticle', this.$route.params.id). The way you have now, your action expects a number, and is passed an object.