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
The transaction log records the operations on the...
Sometimes we build a file server through nginx, w...
1. Display effect: 2, html structure <div clas...
one. Mysql Binlog format introduction Mysql binlo...
Table of contents 1. Installation 2. Use Echarts ...
1. Download Go to the Apache official website htt...
Upgrade process: Original system: CentOS7.3 [root...
Docker installation (Alibaba Cloud Server) Docker...
1. There are many Python version management tools...
Table of contents Preface: Step 1: Find the free ...
Difference between HTML and XHTML 1. XHTML elemen...
This article example shares the specific code of ...
Table of contents 1. Initialize the map 2. Map Po...
To improve the performance of web pages, many dev...
This article example shares the specific code for...