1. Anti-shake functionAssuming that the interval between two Ajax communications must not be less than 2500 milliseconds, the above code can be rewritten as follows. $('textarea').on('keydown', debounce(ajaxAction, 2500)); function debounce(fn, delay){ var timer = null; // declare timer return function() { var context = this; var args = arguments; clearTimeout(timer); timer = setTimeout(function () { fn.apply(context, args); }, delay); }; } In the above code, as long as the user presses the key again within 2500 milliseconds, the previous timer will be canceled and a new timer will be created. This ensures that the interval between callback function calls is at least 2500 milliseconds. 2. Use debouce anti-shake function in Vue Creates a
When Lodash debouce parameters:
<template> <el-input v-model="value" size="mini" placeholder="Please enter.." clearable @keydown.enter="handleSearch" ></el-input> </template> <script> import _ from 'lodash' export default { data() { return { value: '' } }, create() { this.handleSearch = _.debounce(() => { // Get the list this.getList(); }, 300); }, beforeDestroy() { //Cancel the anti-shake call of this function this.handleSearch.cancel(); }, } </script> This is the end of this article on how to use the debouce anti-shake function in Vue. For more information about using the debouce anti-shake function in Vue, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Linux Autofs automatic mount service installation and deployment tutorial
>>: Let's talk about MySQL joint query in detail
Copy code The code is as follows: <span style=...
1. Download the gitlab image docker pull gitlab/g...
This article shares the summary of the JS mineswe...
When key is not added to the v-for tag. <!DOCT...
Hyperlinks enable people to jump instantly from pa...
1 Introduction When we write SQL statements to op...
Table of contents docker system df docker system ...
Table of contents Vue3 encapsulation message prom...
border-radius:10px; /* All corners are rounded wi...
introduce In a distributed system, distributed lo...
The inline-block property value becomes very usef...
The table structure is as follows: id varchar(32)...
Table of contents specification a. The page file ...
PS: I've recently been reading the Nginx chap...
The file name of the dynamic library file under L...