Answer the question
In order to leave comments, you need to log in
How laravel to pass data from controller to component vue.js for spa?
There is an api route:
Route::namespace('Api')->group(function () {
Route::get('/articles', '[email protected]');
});
public function index()
{
return Articles::orderBy('id', 'desc')->Simplepaginate(10);
}
$article->description
$article->created_at,
$article->author->name (Тут через связь в модели можно получить автора статьи)
export default {
data() {
return {
articles: null,
error: null,
loading:false,
};
},
created() {
this.fetchData();
},
methods: {
fetchData() {
this.error = this.users = null;
this.loading = true;
axios
.get('/api/articles')
.then(response => {
this.loading = false;
this.articles = response.data.data;
}).catch(error => {
this.loading = false;
this.error = error.response.data.message || error.message;
});
},
},
v-for="{description,created_at } in articles" ... {{ description }}
($article->author->name)
articles.author.name
or author.name
Answer the question
In order to leave comments, you need to log in
Further, like this, for example, you can display the data of the article itself in vue
And yet, you won’t believe it, it’s possible in another way:
Accordingly, the author of the article will be available asa.author.name
(unless, of course, you are not deceiving about the data structure).
Well, or by analogy with description and created_at, do it through destructuring (by the way, who advised you to do this? - you would read the official documentation instead):
In this case, itauthor.name
will be OK.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question