I'm trying to check each comment and comment reply made by the user and check if they made the comment more than 30 mins ago then they can't edit it, however the way I'm doing it isn't working and I'm getting this error
[Vue warn]: You may have an infinite update loop in a component render function.
This is the code in question
<div v-for="comment in forum.comments">
<el-card shadow="never">
//check for other things
//set the comment info and layout
<div style="text-align: end" v-if="comment.user_id === $page.auth.user.auth.user.id">
{{minutes(comment)}}
<div v-if="editRemove === false" class="btn-link-edit action-button"
@click="edit(comment)">
<i class="fas fa-pencil-alt"></i>
</div>
</div>
<div v-for="reply in comment.replies">
//check for other things
//set the reply info and layout
<div style="text-align: end" v-if="reply.user_id === $page.auth.user.auth.user.id">
{{minutes(reply)}}
<div v-if="editRemove === false" class="btn-link-edit action-button"
@click="edit(reply)">
<i class="fas fa-pencil-alt"></i>
</div>
</div>
</div>
</el-card>
</div>
data return
editRemove: false,
method
minutes(item) {
var minutes = moment().diff(moment(item.comment_time), 'minutes');
if (minutes >= 30) {
this.editRemove = true;
} else if (minutes <= 29) {
this.editRemove = false;
}
}
What should I do to fix this?
} else if (minutes <= 29) {to} else {. ALso you can write it much shorter withthis.editRemove=minutes >= 30minutes(comment), you are editing the same variableeditRemovein that function. So you are constantly changing that same variable value.editRemove, all comments and replies need to have an unique identifier.