I have a project that I'm converting to Vue, and I was wondering how I can conditionally add a class to certain elements depending on what is returned from the database and rendered with Vue. Here is the code I had for the application when I was not using Vue:
$(document).ready(function() {
$('.task_element').each(function(index, element) {
if ($(element).find(".task_priority").text().trim() === "high") {
$(element).addClass('high');
} else if ($(element).find(".task_priority").text().trim() === "medium") {
$(element).addClass('medium');
} else if ($(element).find(".task_priority").text().trim() === "low") {
$(element).addClass('low');
}
});
});
And this worked fine. But, I'm wondering is there a way to do this with Vue much more easily? Or would I have to find a way to throw this into my Vue app?
Here is part of the component:
<p class="task_description">
{{ task.description }} <span class="badge badge-pill">priority</span>
</p>
<p class="task_priority">
{{ task.priority }}
</p>
What I want to do is bind the style of the badge (add one of the classes, either high, medium, or low) based on the value of the task_priority element. How would I achieve this?