Answer the question
In order to leave comments, you need to log in
Am I working correctly with components in vue?
Hey!
I need expert advice, please tell me if I'm doing the right thing, because just learning, this is my first project on vue (backend - laravel). There is a task: to display an article and comments to it. I singled out 2 components (article, comments). I pass the article through props.
export default {
props: [
'news'
]
}
export default {
data : {
comments : null
},
mounted() {
this.update();
},
methods: {
'update' : function() {
axios.get('/news/getCommentsList').then( (response => {
console.log(response.data);
this.comments = response.data;
}) )
}
}
}
Answer the question
In order to leave comments, you need to log in
Well, you asked for an article, didn't you? save the article id and use it when requesting comments.
but in general, in a correct way, the id of the article should be in the url line
and then drag this id through the methods of the router
methods: {
getNewsComments() {
const newsId = this.$route.params.id
axios.get(`/news/${newsId}/comments`).then(...)
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question