Skip to content

Could not make debounce to work #327

Closed Answered by aleclarson
fkdp06 asked this question in Q&A
Discussion options

You must be logged in to vote

@fkdp06 You can use the Radashi debounce in your code like so:

<template>
    <input v-model="searchText" @update:modelValue="onSearch()"/>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { debounce } from "radashi";

export default defineComponent({
    data() {
        return {
            searchText: ""
        }
    },
    methods: {
        onSearch() {
            // Do the site search
        },
    },
    // Use beforeMount since you don't need debouncing in SSR context.
    beforeMount() {
        this.onSearch = debounce({ delay: 500 }, this.onSearch)
    }
});
</script>

Using radashi instead of your own implementation has the following benefits:

  1. L…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@fkdp06
Comment options

@aleclarson
Comment options

Answer selected by fkdp06
@fkdp06
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants