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
We hope to insert the weather forecast into the w...
This article summarizes the principles and usage ...
There are two meta attributes: name and http-equiv...
HTML comments, we often need to make some HTML co...
Table of contents Preface Is the interviewer aski...
<p><b>This is bold font</b></...
1. What is the cardinality? Cardinality refers to...
Tomcat is a web server software based on Java lan...
This example takes the installation of Python 3.8...
Strictly speaking, nginx does not have a health c...
A web server can build multiple web sites with in...
This article installs Google Input Method. In fac...
Transactions ensure the atomicity of multiple SQL...
Redis uses the apline (Alps) image of Redis versi...
1. Problem During development, when inserting dat...