Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Vue.js variable/parameter inside v-if condition

I need to pass a dynamic variable into v-if attribute. I tried multiple ways but it doesn't produce the expected result.

So far, I have this: v-if="customDropdown === {{row.name}}"

How can I conditionally and dynamically render the element, please? Thank you in advance.

like image 876
Kanagaraj Subramaniam Avatar asked Mar 06 '26 13:03

Kanagaraj Subramaniam


1 Answers

You cannot use interpolation in Vue directives/attributes.

To bind to v-if or v-for use variables directly:

<div v-if="value.someProperty"></div>

To bind to other attributes/properties use v-bind: or shorthand : as follows:

<div :directive="value"></div>

Template Syntax documentation

like image 165
Dawid Zbiński Avatar answered Mar 08 '26 03:03

Dawid Zbiński



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!