Skip to content

Debouncing an input event listener #198

Answered by larryhudson
larryhudson asked this question in Q&A
Discussion options

You must be logged in to vote

I found that petite-vue's markdown example uses lodash's debounce function:
https://github.com/vuejs/petite-vue/blob/71aefbf2d79852cdc3ccd63b7d3c79221f7c5fb4/examples/markdown.html

I got this working in my codepen fairly easily, so this is an ok solution for now!

Here's a code example for posterity:

<h1>petite-vue - hypothetical search</h1>

<div v-scope>
  <label>Search</label>
  <input name="q" v-model="searchInput" @input="getSearchResults" />

  <p v-if="searching">Searching...</p>

  <div v-if="searchResults.length > 0">
    <h2>Search results</h2>
    <ul>
      <li v-for="searchResult in searchResults">
        {{searchResult}}
      </li>
    </ul>
  </div>
</div>


<script src="h…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by larryhudson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant