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

128
Visualizações
Using v-btn to change route only if some condition is met

How can i prevent this button from firing to the that url path??

I'm trying to make a method check based on some logic and then if it doesn't pass I need to prevent this button from doing anything.

Any help would be much appreciated:)

<v-btn
  @click="checkIfCanCreateTO($event)"
  :to="{ name: 'New', params: { selected: selectedItems, readonly: false } }"
 >
  <v-icon small class="mr-2">mdi-account-plus</v-icon>
  Create New with
  {{ selectedItems.length }} item(s)
 </v-btn>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If you don't want the button to change route every time it is clicked but do it conditionally, do not use to prop!

Use only @click handler, check your conditions and then use $router.push({ name: 'New', params: { selected: this.selectedItems, readonly: false } }) inside the handler...

about 4 years ago · Juan Pablo Isaza Relatório

0

Have you tried this?

<v-btn
  @click.prevent="checkIfCanCreateTO($event)"
  :to="{ name: 'New', params: { selected: selectedItems, readonly: false } }"
 >
  <v-icon small class="mr-2">mdi-account-plus</v-icon>
  Create New with
  {{ selectedItems.length }} item(s)
</v-btn>

Supplement to the answer

You can add "prevent events" to the function

checkIfCanCreateTO(event) {
  event.preventDefault();
  // your code
}
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