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

270
Views
@click ternary operations in Vue.js

I'm trying to do the following but it keeps returning [plugin:vite:vue] Unexpected token (1:27) error in Vue.js:

@click="selectedFiles.push(file.id); selectedFiles.length < 1 ? isCollapse=false: isCollapse=true"

Basically when this image is clicked:

  1. It should first push the file to selectedFiles array
  2. .. and then check if the length is < 1 and change the isCollapse boolean accordingly.

The code works fine without the ternary operation so I believe it's a syntax issue.

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

0

Did you try like:

@click="[selectedFiles.push(file.id), isCollapse = !!selectedFiles.length]"
about 4 years ago · Juan Pablo Isaza Report

0

You can actually avoid the ternary entirely.

isCollapse = selectedFiles.length >= 1

As far as ternary syntax goes spaces on either side of the colon are important.

selectedFiles.length < 1 ? isCollapse = false : isCollapse = true

Also, I would definitely recommend using a method for this. Any time you need to perform more than 1 very simple js expression in response to an event, a method will be much more readable and maintainable.

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!