I am using List Rendering (v-for) in my project to print each item in my array to show information on a series of books.
However, I am trying to use conditional rendering within this loop, in order to print a number of li elements that contain the book's category tag.
I do not want the li to be painted in the DOM if there is no data stored in my array. For example, for the first book, Moby Dick, the ul for the book tags would just contain two HTML list items.
How can this be done? I have the following so far ...
<ul>
<li v-for="book in books">
<div class="item">
<div class="item-bd">
<h2>{{ book.title }}</h2>
<ul class="book-tags>
<li v-if="">{{book.tagOne}}</li>
<li v-if="">{{book.tagTwo}}</li>
<li v-if="">{{book.tagThree}}</li>
</ul>
</div>
</div>
</li>
</ul>
new Vue({
el: '#app',
data: {
books: [
{
title: "Moby Dick",
tagOne: "Kids Book",
tagTwo: "Fiction",
tagThree: ""
},
{
title: "Hamlet",
tagOne: "All Ages",
tagTwo: "Shakespeare",
tagThree: "Classic"
}
]
}
});
v-for). If you want to stick to three fixed tags, just usev-if="book.tagOne". The fact that this is happening inside av-forlist doesn't matter one bit, afaik.