[Vuejs]-How to add class in v-if Vue.js

4👍

<td v-for="option in selected_type" :key="option.id" :class="{ inactive: item.status }">

I’m assuming the status property is a boolean
(Not sure why you’re comparing the id with the status also)

.inactive { color: red; }
👤Renaud

3👍

A simple example, presuming that status is boolean:

new Vue({
  el: "#app",
  data: {
    items: [
      { label: 'foo', status: true },
      { label: 'bar', status: false }
    ]
  }
})
.text-red {
  color: red;
}
<script src="https://cdn.jsdelivr.net/npm/vue"></script>

<div id="app">
  <p v-for="item in items" v-bind:class="{ 'text-red': item.status }">
    {{item.label}}
  </p>
</div>
👤Vucko

Leave a comment