1
<div class="container" :class="{ qwerty: !open }" :class="lower? 'left' : 'right'">

Hi, why vue doesn't allow me to add several classes with conditions, like in example.
It allows to add one only.
How to implement this?

3 Answers 3

2

Use Array Syntax.

:class="[lower ? 'left' : 'right', upper ? 'up' : 'down']"
Sign up to request clarification or add additional context in comments.

Comments

1

There are multiple ways to do this, but I think for you it should be enough to do this:

:class="[{qwerty: !open}, lower ? 'left' : 'right']"

it's a mix from passing an array of classes and passing objects

Comments

1

If you have multiple conditions that goes too lengthy including too many logics then go with computed

<div class="container" :class="getClass">

then

computed: {
 getClass() {
  var className = 'container';
  if(!this.open) className = className+' '+'querty';

  if(this.lower) className = className+' '+'left';
  else className = className+' '+'right';

  return className;
 }
}

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.