Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Vue v-if equal or contains

Can anyone please show me how to do this, I have a image with alt than contains alt="#color_blue" or alt="#color_orange", I call this data with Liquid as {{ media.alt }}

that I want to do is if the 'current_variant.alt' == {{ media.alt }} return true and also if the 'current_variant.alt' contain '#' return too true as well.

<div v-if="current_variant.alt == '{{ media.alt }}' && current_variant.alt == '#'">

</div>

I don't know how to let current_variant.alt check if the {{ media.alt }} contains #

like image 657
Elkazi Avatar asked Nov 08 '25 01:11

Elkazi


2 Answers

You can use the string.includes method to check if a string contains a particular character.


If you want to check if current_variant.alt equals media.alt:

current_variant.alt == '{{ media.alt }}'

If you want to check if current_variant.alt contains '#':

current_variant.alt.includes('#')

If you want to check if media.alt contains '#':

'{{ media.alt }}'.includes('#')
like image 113
TheNightHawk Avatar answered Nov 09 '25 15:11

TheNightHawk


To check if current_variant.alt contain #, use Javascript "includes" => current_variant.alt.includes('#')

<div v-if="current_variant.alt == media.alt && current_variant.alt.includes('#')">    
</div>
like image 36
Juhuang Xue Avatar answered Nov 09 '25 15:11

Juhuang Xue



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!