Anti-shake: Prevent repeated clicks from triggering events First of all, what is shaking? Shaking is a shiver! Originally I clicked once, now I clicked 3 times! I wonder if my friend has a good sense of picture in his mind! Hahahahahaha A typical application is to prevent users from repeatedly clicking to request data. Vue implements anti-shake method as follows: 1. First, create a new debounce.js code as follows const debounce = function (fn, delay) { let timer = null return function(){ let content = this; let args = arguments; if(timer){ clearTimeout(timer) } timer = setTimeout(()=>{ fn.apply(content,args) }, delay) } } export default debounce 2. Introduce debounce in the vue file that needs anti-shake, the content is as follows; this is a 500ms anti-shake of an input box <template> <div class="main"> <el-input v-model="input" @change="changeSeletc" placeholder="Please enter content"></el-input> </div> </template> <script> import debounce from "../utils/debounce" export default { name: "alarm", data(){ return { input: '' } }, methods:{ changeSeletc:debounce(function () { console.log(this.input) },500), } } </script> <style scoped> </style> 3. The effect is as shown below Summarize This is the end of this article about Vue's anti-shake implementation. For more relevant Vue anti-shake content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of uniapp's global variable implementation
>>: Detailed explanation of the usage of Object.assign() in ES6
This article shares the specific code of vue+swip...
Problem Description When filter attribute is used...
Data backup and restore part 3, details are as fo...
1. Basic Specifications (1) InnoDB storage engine...
1. Only Chinese characters can be input and pasted...
In this article, we will analyze the production of...
It is also very simple to deploy Django projects ...
This article shares the specific code for js to r...
This article shares the specific code of js to ac...
Table of contents Props comparison of class compo...
# The following examples are for x64-bit runtime ...
In the following example, when the width of the td...
HTML5 adds more semantic tags, such as header, fo...
This article shares a common example of viewing p...
Table of contents 1. Commonjs exports and require...