Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

274
Visualizações
@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 Respostas
Responde à pergunta

0

Did you try like:

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

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda