Answer the question
In order to leave comments, you need to log in
How to get data from template in computed method in vue?
<div id="commentsBlock"><vue-comments-item :model="treeComments"></vue-comments-item></div>
Vue.component('item', {
template: '' +
'<item>' +
'<li v-for="comment in model">' +
'<div>{{comment.users.username}}<br />{{comment.text}}</div>' +
'<ul :model="comment" v-if="replies">' +
'<vue-comments-item v-for="model in comment.replies" :model="model"></vue-comments-item>' +
'</ul>' +
'</li>' +
'</item>' +
'',
props: {
model: Object
},
computed: {
replies: function () {
console.log(JSON.stringify(this.model, null, 4));
}
},
})
Answer the question
In order to leave comments, you need to log in
Make the method simple:
methods: {
replies(v){
// some code
}
}
<ul :model="comment" v-if="replies(comment)">
I could be wrong, so I'm not trying to be the answer. But computed is not a method, but a variable that is pre-calculated.
computed: {
replies: function () {
return 2+2;
}
},
<p>{{ replies }}</p>
// 4
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question