Answer the question
In order to leave comments, you need to log in
How to implement adding classes to vue list via computed?
Good afternoon.
There is such a list (the code works):
<tr v-for="job in jobs" :key="job._id" :class="[
job.state,
job.isRead ? '' : 'no-read',
new Date() >= Date.parse(job.finalDate) ? 'overdue' : ''
]">
<td>{{ job.subject }}</td>
<td>{{ job.executor }}</td>
</tr>
<tr v-for="job in jobs" :key="job._id" :class="jobClass(job)">
<td>{{ job.subject }}</td>
<td>{{ job.executor }}</td>
</tr>
computed: {
jobClass: function(job) {
return {
done: job.state,
break: job.state,
//...
}
}
}
Answer the question
In order to leave comments, you need to log in
writes that jobClass is not a function
if you use computed to work with classes, then it looks like this
countColor() {
return {
red: this.comment.rating.count < 0,
green: this.comment.rating.count > 0,
};
},
categoryTitle() {
let catTitle = '';
if (!this.$route.params.category) {
catTitle = 'Новости<br> игрового мира';
}
if (this.$route.params.category === 'news') {
catTitle = 'Новости';
}
if (this.$route.params.category === 'articles') {
catTitle = 'Статьи';
}
return catTitle;
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question