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

127
Views
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 answers
Answer question

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 Report

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 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!