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
If you want to become a Linux master, then master...
1 Effect Demo address: https://www.albertyy.com/2...
This article will introduce how to use radial-gra...
View the installation information of mysql: #ps -...
1. After connecting and logging in to MySQL, firs...
Four network types: None: Do not configure any ne...
This article shares the installation and configur...
Effect There are currently 2 projects (project1, ...
We know that the properties of the select tag in e...
Table of contents 1. Install Docker 2. Install Gi...
Table of contents 1. Introduction 2. Prepare the ...
The GtkTreeView component is an advanced componen...
The equal height layout described in this article...
Table of contents infer Case: Deepen your underst...
When the table header is fixed, it needs to be di...