S
S
Sergey Khlopov2019-09-20 11:31:51
Vue.js
Sergey Khlopov, 2019-09-20 11:31:51

Is there any easy replacement for lodash.debounce?

Hello, tell me please, I have such a component:

<template>
    <div class="search">
        <input name="search" type="text" class="search__input" v-on:input="fnSendSearch">
    </div>
</template>
<script>
    import lodash from 'lodash';
    export default {
        model: {
            prop: 'query',
            event: 'query-search',
        },
        data: function() {
            return {
                query: null,
                fnSendSearch: Function,
            }
        },
        created: function() {
            this.fnSendSearch = lodash.debounce(this.sendSearch,300);
        },
        methods: {
          sendSearch: function(event) {
              this.$emit('query-search',event.target.value);
          }
        },
    }
</script>

This is a search component, all it does is send an event when the user enters something into the input after 300ms, the problem is that I am pulling up the whole library lodashjust for one thing.lodash.debounce(this.sendSearch,300); Please tell me if there is any alternative not to pull up the whole library. Thank you in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
grinat, 2019-09-20
@Shlop

https://learn.javascript.ru/settimeout-setinterval lodash works via settimeout
Yes, and in fact, you can do import debounce from 'lodash/debounce' and then only what is required will be in the bundle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question