Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining conditional and non-conditional classes in vue

I need to set a class using vue the value in a vue param. Additionally, I need to conditionally set a class based on if a vue param is a certain value. Is it possible to combine the two below functionalities in to one class assignment?

<button :class="'btn btn-primary modal modal-' + modal.id" 
        :class="{'modal-active' : modal.active}">
</button>
like image 595
AnchovyLegend Avatar asked Oct 23 '25 00:10

AnchovyLegend


1 Answers

You could do it as follows by using an array :

   <div v-bind:class="[{'modal-active' : modal.active}, 'btn btn-primary modal modal-' + modal.id]"></div>
like image 94
Boussadjra Brahim Avatar answered Oct 25 '25 14:10

Boussadjra Brahim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!