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

257
Views
How to Overwrite or Refresh javascript setTimeout

I need to refresh or overwrite setTimeout delay value.. I have a product quantity update button:

<q-input class="q-pb-none" v-model="quantity" dense borderless style="width: 25px" mask="###" @input="updateQty" />
<div class="col-auto">
          <div class="row"><q-icon name="keyboard_arrow_up" @click="quantity++" class="cursor-pointer"/></div>
          <div class="row"><q-icon name="keyboard_arrow_down" @click="quantity--" class="cursor-pointer"/></div>
        </div>

I don't want to make update request on every clicking of qty change buttons, instead of this following updateQty function should run 3 seconds later then user give up to click the button.

updateQty () {
// I need to refresh this timeout at evertime this function called.
      window.setTimeout(() => {
        this.$store.dispatch('pack/updateProductQty')
      }, 3000)
    }

How can I set this logic? I use quasar vue.js framework. Thank you..

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

0

You can set the timeout id into a variable and clear the timeout on each click:

let timeoutId;

updateQty () {
    if (timeoutId) {
        clearTimeout(timeoutId);
    }
    timeoutId = window.setTimeout(() => {
        this.$store.dispatch('pack/updateProductQty')
    }, 3000)
}

IMHO a cleaner solution would be using Observables or similar technique.

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!