The debounce functionality provided by Lodash does not seem to be functioning properly within VueJS events

I am attempting to incorporate the debounce function into my filter. The goal is to avoid sending a request with each change in input text, and instead, wait for about one second.

However, I'm encountering an issue where the filter doesn't seem to be triggered at all when using _.debounce.

  <div class="md-form">
        <i class="fas fa-search prefix"></i>
        <input type="text" class="form-control" v-model="filter.fulltext" @input="runFilter" id="x">
        <label for="x">Fulltext search</label>
  </div>

var app = new Vue({
        delimiters: ['[[', ']]'],
        el: '#app',
        data: { ....
        methods:{
            runFilter() {
                var self = this;

                _.debounce(function () {
                    self.records_page = 1;
                    self.loadRecords();
                    self.loadMarkers();
                 }, 1000)

               },
               ....

Any idea why the function is not being triggered after one second?

Answer №1

The _.debounce() method creates a function with closure, requiring you to choose a location to store the debounced function. Typically, the debounced function is assigned to a property on 'this' within the created hook.

created() {
   this.debouncedGetAnswer = _.debounce(this.getAnswer, 500)
}

Refer to the official documentation for a similar implementation: https://v2.vuejs.org/v2/guide/computed.html

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing NextJS to retrieve cookie data within React components

Currently, I am working with a Next.js frontend and an Express backend. For authentication, I am utilizing cookies and have set up protected routes using Next.js middleware. The next step in my project involves accessing the cookie response within React ...

The jQuery slider does not have the functionality to be dragged

My Ruby on Rails app is utilizing a jQuery slider, but I am encountering an issue where I am unable to drag the slider button. However, it does move successfully if I click anywhere inside the slider. Here is the code snippet: <div id="slider">< ...

Max value determined by a variable within a for loop

UPDATE: Revised code provided. In my Node.js JavaScript project, I am creating a script to iterate through a dataset obtained by web scraping. The main goal of this algorithm is: 1) Examine the player table for the presence of the player's name in a ...

Can you tell me the method of checking the number of members in a voice channel?

Is there a method to determine the number of members in a voice channel or check if it's empty using discord.js (V. 13.8.1)? I attempted the following code: async function countMembers(voiceState){ let users = await voiceState.channel.members.siz ...

Using dynamic import to pull in the map from an npm package.json in JavaScript

Is there a way to set up path mapping for pure JavaScript imports? Currently, when we want to import npm packages in pure JS without using webpack, the syntax is different. Instead of just using import package from 'package-name', we have to use ...

Learn how to create a "generated" texture coordinate in three.js similar to how it is done in Blender Cycles

How can I properly display a texture on a cylinder object using THREE.js without distortion? Currently, the texture appears stretched along the edges of the cylinder as shown here: https://i.sstatic.net/O2YFr.png This issue is based on the texture provide ...

Initial value in array remains unchanged

I have implemented a functionality where images work like checkboxes, but I am facing an issue where the first selected element does not receive the added class. <div v-for="tenant in shops" :key="tenant.id"> <div class="" style="position: rela ...

Setting up Visual Studio Code for debugging HTML and JavaScript code

Struggling to troubleshoot some HTML/JavaScript using VSCode. After installing the Chrome debugger extension and configuring the launch.json as follows: { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of ex ...

Issue with JavaScript ScrollTop

Simply put, I am trying to determine the total scroll size for a text area in a unit that scrollTop can align with. However, I am at a loss on how to do so. I've tried scrollHeight and various other methods without success. Any advice or suggestions ...

implementing a timestamp in a specific timezone with Vue.js

Utilizing a timestamp attribute, I have successfully implemented the display of the current time and date on my webpage. Is there a way to showcase this information in a specific time zone? I am looking to present it in the ZULU timezone, which remains st ...

Iterating through a collection of items in Vue.js using the v

I am attempting to cycle through an object using v-for. exampleObject =[a,b,c,d] Requirement = display only a if it exists in exampleObject, otherwise show b, c, d. <div v-if="checklist.types"> <div v-for="type in checklist.t ...

React.js Form Validation issue: When using input type "number", the text field remains a single value even after attempting to delete characters with the backspace key

Experiencing difficulty in clearing the input field value, even after pressing backspace the value remains constant. One particular value persists in the input field. import * as React from "react"; import { Button, Form } from "react-boots ...

Breaking Down the Process of Exporting a Next.js Static Website into Manageable Parts

I am facing memory issues while building my website using Next.js's Static HTML Export. The site has a large number of static pages, approximately 10 million. Is it feasible to export these pages in batches, like exporting 100k pages in each build ite ...

The functionality of Bootstrap tabs is compromised when used within a modal dialog

I am encountering an issue while using Django and Bootstrap to implement nav-tabs within a modal that is displayed upon clicking a button. The problem lies in the fact that when a tab is clicked, its content does not appear. Below is a basic example: {% ...

Is there a way to keep my fixed button at a consistent size while zooming on mobile devices?

There are no definitive answers to the questions regarding this issue. Some suggest stopping zoom altogether, while others recommend setting the width, which may not always solve the problem. I am working on a web application designed for mobile use with ...

Trying to use the `await` keyword results in a "SyntaxError: Unexpted identifier" message, even when used within an `async` function

Encountering an error with Javascript's await when using it inside an async module let ImagesArray = await getImages(); ^^^^^^^^^ SyntaxError: Unexpected identifier at createScript (vm.js:80:10) at Object.runInThis ...

Different boolean variable assigned to every item in v-for loop

I am working on creating a custom play/pause button for my audio elements, and here is how I have implemented it: <div v-for="(post, p) in post_list"> <!-- ... --> <!-- ... --> <!-- ... --> <v-avatar v-i ...

Exploring the Diversity of Forms with Ajax and JQuery

$(document).ready(function () { $("#addrow").click(function () { var newRow = '<tr><td><input type="text" class="item_code form-control" placeholder="Item Code" name="item_code[]"></td><td><input type="text" ...

What should I designate as the selector when customizing dialog boxes?

I am attempting to change the title bar color of a dialog box in CSS, but I am running into issues. Below is the HTML code for the dialog box and the corresponding CSS. <div id="picture1Dialog" title = "Title"> <p id="picture1Text"> ...

Assigning websockets to a global variable may cause them to malfunction

I'm utilizing websockets in conjunction with JavaScript and HTML5. Here is the code snippet I am currently working with: <input type="text" onFocus="so = new Websocket('ws://localhost:1234');" onBlur="so.close();" onKeyUp="keyup();"> ...