当前位置:网站首页>Button can only be clicked once
Button can only be clicked once
2022-08-06 07:53:00 【_rosy】
Today when I was using the add button to add records, I suddenly added several records, which left me stunned.Then it responded that the server did not respond because the network was stuck and the request was sent repeatedly.
Crazy prompt added successfully~~~

Today I share two methods:
The first uses the once event modifier
Use @click.once to realize that the button can only be clicked once, which is suitable for submitting form records or performing database operations
- once, only execute once
- Only the first click will execute, a second click will not work
OK
The second way to customize one
Custom methods can be written in a js file for reuse.This is a reference to an article by a big guy, but I feel that it is not enough for the specific use, so I will use my own example to demonstrate it.
First I choose to create a clickThrottle.js file under the components file under src
clickThrottle.js file content:
/* prevent repeated clicks */let clickTimer = 0function clickThrottle(interval = 3000) {let now = +new Date(); // get the timestamp of the current timelet timer = clickTimer; // record the event stamp of the trigger eventif (now - timer < interval) {// If the current time - the event when the event was triggered < interVal, then the condition is not met, return false directly,// Don't let the current event continue to executereturn false;} else {// On the contrary, record the timestamp of the event that meets the conditions, and return true, so that the event continues to be executedclickTimer = now;return true;}}export default clickThrottleImport files
import antiShake from '@/components/clickThrottle'

Use:

Well, I call this wave of mother-level teaching. If it is helpful to you, please like, comment and bookmark (o´ω`o)و
Rendering: 
Reference article address: http://t.csdn.cn/9g1m3
边栏推荐
- 记录自己LitJson解析Json的方法
- vivado2022.1 仿真找不到gcc
- 跳表的实现
- unity 使用paint in 3d实现画板效果
- C语言力扣第59题螺旋矩阵②。模拟矩阵
- qwqの科技flag
- Simulate the realization of strcpy function (including multiple optimization ideas)
- 一文3000字解析Pytest单元测试框架【保姆级教程】
- [ CTF ]【天格】战队WriteUp-第六届“强网杯”全国安全挑战赛(初赛)
- Why do interviewers keep asking technical questions on your resume until they can't answer them?
猜你喜欢
随机推荐
猴子都能上手的PUN扩展(房间密码,房间列表,RTC)
C language force buckle the 59th spiral matrix ②.analog matrix
How can machinery manufacturing companies use ERP systems to manage production schedules?
百度编辑器的使用坑
猴子都能上手的Unity插件Photon之重要部分(PUN)
CSDN official plug-in
猴子都会用的Unity路径移动工具
vivado2022.1 仿真找不到gcc
Unity UI的自动排版
LeetCode——345. 反转字符串中的元音字母
上线的项目数据库属性添加
快速学会文件操作模块
MySQL数据库 优化
Unity NavMesh基础自动寻路
Chapter 13 Bayesian Network Practice
Use Specification and Example to implement dynamic conditional query cases
【engine】在ui线程里同步调用get、set
记录自己LitJson解析Json的方法
WPF 实现柱形统计图
不会吧,不会吧都2022年了你不会还不知道Jmeter原理吧

![[Cloud Native--Kubernetes] Configuration Management](/img/ef/37732ff3ec1b3609ba53d876ad8178.png)







