0

I am trying to hide a div element using the v-if directive in an HTML element like so:

<template v-if="(selectedProducts != 'Static Graphic' || selectedProducts != 'Other Support')">
  <div><strong>Content 2 Here</strong></div>
</template>

But, this doesn't work.

What's the correct way to write this logic/expression? MY JSFIDDLE demo

Thank you,

1
  • So it seems that according to the VueJS docs, multiple expressions are not allowed in directives in VueJS2. Did I read that right? I should move this logic into the computed property? Commented Sep 14, 2017 at 14:34

2 Answers 2

1

You can put an expression in v-if. The problem is with your expression: selectedProducts is an Array, you can't test selectedProducts != 'Static Graphic'

Try this:

v-if="(selectedProducts.indexOf('Static Graphic') < 0  && selectedProducts.indexOf('Other Support') < 0)">

jsfiddle: https://jsfiddle.net/thierry36t/x2kc55p0/1/

Sign up to request clarification or add additional context in comments.

Comments

0

VueJS has awesome documentation so You should take a look here first https://v2.vuejs.org/v2/guide/conditional.html

Here You can skip template tag and move v-if into the div like this:

<div v-if="selectedProducts != 'Static Graphic' || selectedProducts != 'Other Support'">
 Now you see me
</div>

Take a look here: https://jsfiddle.net/bqe05f2w/1/

Update for Your particular case:

<template v-if="selectedProducts.indexOf('Static Graphic') > 0 || selectedProducts.indexOf('Other Support') > 0">
  <div><strong>Content 2 Here</strong></div>
</template>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.