Dzonikas
Dzonikas

Reputation: 13

Changing style of element in Vue depending on true/false from element in api

How to change style(color) of paragraph in Vue if element (boolean) from api returns true

<p v-if="discount = false">Discount</p>

Upvotes: 0

Views: 4755

Answers (1)

Niek van der Maaden
Niek van der Maaden

Reputation: 482

You can use the class binding v-bind:class or shorthand :class to accomplish this. Same goes for v-bind:style | :style

Example:

<p :class="{ 'someClass': discount, 'someotherClass': !discount }">Discount</p>

Resource: VueJS Class and Style binding

Upvotes: 1

Related Questions