So I am using vuejs and trying to add a ternary operator or something that will not force the v-bind class to apply. Even if the data is false, it still applies the css class. how do I prevent this?
new Vue({
el: '#cal',
data: {
January: 'no',
February: 'no',
March: 'no',
April: 'yes',
May: 'yes',
June: 'yes',
July: 'no',
August: 'no',
September: 'no',
October: 'no',
November: 'no',
December: 'no'
}
})
table,
th,
td {
border: 1px solid black;
}
th {
width: 100px;
height: 100px;
background-color: white;
}
td {
background-color: grey;
}
.January {
background-color: pink;
}
<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<table>
<div id="cal">
<tr>
<th>Jan</th>
<th>Feb</th>
<th>Mar</th>
<th>Apr</th>
<th>May</th>
<th>Jun</th>
<th>Jul</th>
<th>Aug</th>
<th>Sep</th>
<th>Oct</th>
<th>Nov</th>
<th>Dec</th>
</tr>
<tr>
<td v-bind: class="{'January' : January == 'yes' }">askjdldsaa</td>
<td v-bind: class="{'February' : February == 'yes'}"></td>
<td v-bind: class="{'March' : March == 'yes'}"></td>
<td v-bind: class="{'April' : April == 'yes'}"></td>
<td v-bind: class="{'May' : May == 'yes'}"></td>
<td v-bind: class="{'June' : June == 'yes'}"></td>
<td v-bind: class="{'July' : July == 'yes'}"></td>
<td v-bind: class="{'August' : August == 'yes'}"></td>
<td v-bind: class="{'September' : September == 'yes'}"></td>
<td v-bind: class="{'October' : October == 'yes'}"></td>
<td v-bind: class="{'November' : November == 'yes'}"></td>
<td v-bind: class="{'December' : December == 'yes'}"></td>
</tr>
</div>
</table>
I have updated the sample to show the issue with the conditional applied. It still renders the pink box even if I changed the data to a "no".
new Vue({
el: '#cal',
data: {
January: 'no',
February: 'no',
March: 'no',
April: 'yes',
May: 'yes',
June: 'yes',
July: 'no',
August: 'no',
September: 'no',
October: 'no',
November: 'no',
December: 'no'
}
})
table,
th,
td {
border: 1px solid black;
}
th {
width: 100px;
height: 100px;
background-color: white;
}
td {
background-color: grey;
}
.January {
background-color: pink;
}
<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<table>
<div id="cal">
<tr>
<th>Jan</th>
<th>Feb</th>
<th>Mar</th>
<th>Apr</th>
<th>May</th>
<th>Jun</th>
<th>Jul</th>
<th>Aug</th>
<th>Sep</th>
<th>Oct</th>
<th>Nov</th>
<th>Dec</th>
</tr>
<tr>
<td v-bind: class="{'January' : January == 'yes' }">askjdldsaa</td>
<td v-bind: class="{'February' : February == 'yes'}"></td>
<td v-bind: class="{'March' : March == 'yes'}"></td>
<td v-bind: class="{'April' : April == 'yes'}"></td>
<td v-bind: class="{'May' : May == 'yes'}"></td>
<td v-bind: class="{'June' : June == 'yes'}"></td>
<td v-bind: class="{'July' : July == 'yes'}"></td>
<td v-bind: class="{'August' : August == 'yes'}"></td>
<td v-bind: class="{'September' : September == 'yes'}"></td>
<td v-bind: class="{'October' : October == 'yes'}"></td>
<td v-bind: class="{'November' : November == 'yes'}"></td>
<td v-bind: class="{'December' : December == 'yes'}"></td>
</tr>
</div>
</table>