Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
Vue js. Several classes with js
<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?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Use Array Syntax.

:class="[lower ? 'left' : 'right', upper ? 'up' : 'down']"
about 4 years ago · Juan Pablo Isaza Report

0

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

about 4 years ago · Juan Pablo Isaza Report

0

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;
 }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!