Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

266
Vistas
@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 Respuestas
Responde la pregunta

0

Did you try like:

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

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda