No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    [SOLVED] Am I using debounce incorrectly?

    Framework
    2
    4
    2142
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ssuess
      ssuess last edited by ssuess

      I am trying to get a function attached to an input to only run after the user has finished typing, but not sure this is the correct way to go about this. Currently I have an input that looks like this:

      <q-input v-model="search" @input="showingDebounce()" ></q-input>
      

      and script that looks like this:

      import { debounce } from 'quasar'
      export default {
        data () {
          return {
            search: '',
            showing: false
          }
        },
        methods: {
          showingDebounce () { debounce(function () { this.showingOn() }, 1000) },
          showingOn () { this.showing = true }
        }
      }
      

      ideally showingDebounce() should (I thought) wait for the user input to have stopped for 1000 ms, then run the showingOn() function, but nothing is happening.

      Am I doing something wrong here? Thanks!

      1 Reply Last reply Reply Quote 0
      • ssuess
        ssuess last edited by ssuess

        Ok, I think I figured this out. I had to attach a watcher to the search and run the debounce function there. @input was the wrong place apparently.

        1 Reply Last reply Reply Quote 0
        • T
          tof06 last edited by

          Hi,

          Since you’re debouncing on q-input model change, I think you can also use debounce=1000 prop of this component (https://quasar.dev/vue-components/input#Debouncing-model)

          1 Reply Last reply Reply Quote 1
          • ssuess
            ssuess last edited by

            omg, thanks! That is way easier than the contortions I had to go through!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post