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

131
Views
Vue JS - Conditional keyup.enter is not working

I'm trying to implement a conditional keyup event, however keyup.enter doesn't get fired when I implement it conditionally using a computed property for @[listenToKeyup].

<template>
   <div>
      <input @[listenToKeyup]="manageSearch"
             v-model="input"
             class="form-input"/>
   </div>
</template>
export default {
    props: {
      skipSearch: {
        type: Boolean,
        required: false,
        default: false
      },
      callback: {
        required: false
      },
    },
  setup(props, {emit}) {
      const input = ref('');

      const listenToKeyup = computed(() => props.skipSearch ? 'keyup.enter' : 'keyup');

      function manageSearch() {
        clearTimeout(searchTimeout)
        searchTimeout = setTimeout(props.callback(input.value), debounce);
      }

  return {
      input,
      listenToKeyup,
      manageSearch,
  };

  }

In this example, props.skipSearch is registered as true in another component and in fact 'manageSearch' does not get fired, whereas in other components where its false, it is fired. This means that the condition in listenToKeyup is being determined, however keyup.enter is not being fired. If I try to add the event without the condition '@keyup.enter="manageSearch"', it works as it should, so there isn't an issue with that either.

Can someone kindly show me what I'm doing wrong, please?

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

0

The problem is the event-modifier.

Dynamic events are possible but modifiers are not supported.

You would have to change your logic to what @Boussadjra Brahim was almost suggesting just with the difference that the modifier has to be written manually:

//manage Search
function manageSearch(event) {
  if (!props.skipSearch|| ["Enter"].includes(event.key)) {
    //do your thing
  }
}

Codesandbox example

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!