Can I render closing tag conditionally with v-if
? And if yes, what's the right way to do it? My first instinct was this:
<template v-for="day in days">
<td class="days">{{day.number}}</td>
<template v-if="day.isSunday">
</tr>
<tr>
</template>
</template>
This works on its own, but it wont render </tr><tr>
raw - is this expected behavior?
And if this is impossible - what is the best way to break a table row conditionally?
My specific case is - days of the month in an array with additional info for them. Each day has a isSunday
property and I want to start a new row after each Sunday (imitating calendar behavior)
Usually i recommend to put the all logic in your script and only use properties and call methods in the template section, so for this case i gonna define a
computed
property calledcptDays
in which i loop through thedays
array and when i meet a normal day i push it in a week if the day is Sunday i push it and i increment the number of weeks, in the end i return themonth
array which i loop through it in my template.Note
i used CSS from bootstrap to give a pretty look, you could remove it and your code will not be changed