Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuetify conditional color parameter on element

I'm using vuetify and it comes with an inbuilt color parameter and some predefined colors. I am dynamically loading data to components and I want the color of the component to be dependent on the datas value, eg. complete: true, then color = green

example of what I'm trying to do

<component :color="'deep-purple accent-4' if item.complete else 'grey'" v-for="n in items"></component>

The above example is rough and not legitimate code but I think highlights what I want to do. I know I could create my own classes and use the conditional class method but if possible Id like to stick with inbuilt Vuetify stuff

like image 233
Ari Avatar asked Oct 26 '25 07:10

Ari


1 Answers

Apart from using a method like you already posted in your answer, you could also do it inline with a ternary-operator.

<component :color="n.complete ? 'green' : 'grey'" v-for="n in items"></component>
like image 179
discolor Avatar answered Oct 28 '25 20:10

discolor



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!